|
1 | 1 | #--
|
2 | 2 | # DO NOT MODIFY!!!!
|
3 |
| -# This file is automatically generated by rex 1.0.5 |
| 3 | +# This file is automatically generated by rex 1.0.7 |
4 | 4 | # from lexical definition file "lib/nokogiri/css/tokenizer.rex".
|
5 | 5 | #++
|
6 | 6 |
|
7 | 7 | module Nokogiri
|
8 | 8 | module CSS
|
9 | 9 | class Tokenizer # :nodoc:
|
10 |
| - require 'strscan' |
| 10 | + require 'strscan' |
11 | 11 |
|
12 |
| - class ScanError < StandardError ; end |
| 12 | + class ScanError < StandardError ; end |
13 | 13 |
|
14 |
| - attr_reader :lineno |
15 |
| - attr_reader :filename |
16 |
| - attr_accessor :state |
| 14 | + attr_reader :lineno |
| 15 | + attr_reader :filename |
| 16 | + attr_accessor :state |
17 | 17 |
|
18 |
| - def scan_setup(str) |
19 |
| - @ss = StringScanner.new(str) |
20 |
| - @lineno = 1 |
21 |
| - @state = nil |
22 |
| - end |
| 18 | + def scan_setup(str) |
| 19 | + @ss = StringScanner.new(str) |
| 20 | + @lineno = 1 |
| 21 | + @state = nil |
| 22 | + end |
23 | 23 |
|
24 |
| - def action |
25 |
| - yield |
26 |
| - end |
| 24 | + def action |
| 25 | + yield |
| 26 | + end |
27 | 27 |
|
28 |
| - def scan_str(str) |
29 |
| - scan_setup(str) |
30 |
| - do_parse |
31 |
| - end |
32 |
| - alias :scan :scan_str |
| 28 | + def scan_str(str) |
| 29 | + scan_setup(str) |
| 30 | + do_parse |
| 31 | + end |
| 32 | + alias :scan :scan_str |
33 | 33 |
|
34 |
| - def load_file( filename ) |
35 |
| - @filename = filename |
36 |
| - open(filename, "r") do |f| |
37 |
| - scan_setup(f.read) |
38 |
| - end |
39 |
| - end |
| 34 | + def load_file( filename ) |
| 35 | + @filename = filename |
| 36 | + File.open(filename, "r") do |f| |
| 37 | + scan_setup(f.read) |
| 38 | + end |
| 39 | + end |
40 | 40 |
|
41 |
| - def scan_file( filename ) |
42 |
| - load_file(filename) |
43 |
| - do_parse |
44 |
| - end |
| 41 | + def scan_file( filename ) |
| 42 | + load_file(filename) |
| 43 | + do_parse |
| 44 | + end |
45 | 45 |
|
46 | 46 |
|
47 |
| - def next_token |
48 |
| - return if @ss.eos? |
49 |
| - |
50 |
| - # skips empty actions |
51 |
| - until token = _next_token or @ss.eos?; end |
52 |
| - token |
53 |
| - end |
| 47 | + def next_token |
| 48 | + return if @ss.eos? |
54 | 49 |
|
55 |
| - def _next_token |
56 |
| - text = @ss.peek(1) |
57 |
| - @lineno += 1 if text == "\n" |
58 |
| - token = case @state |
59 |
| - when nil |
60 |
| - case |
61 |
| - when (text = @ss.scan(/has\([\s]*/)) |
62 |
| - action { [:HAS, text] } |
| 50 | + # skips empty actions |
| 51 | + until token = _next_token or @ss.eos?; end |
| 52 | + token |
| 53 | + end |
63 | 54 |
|
64 |
| - when (text = @ss.scan(/[-@]?([_A-Za-z]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*\([\s]*/)) |
65 |
| - action { [:FUNCTION, text] } |
| 55 | + def _next_token |
| 56 | + text = @ss.peek(1) |
| 57 | + @lineno += 1 if text == "\n" |
| 58 | + token = case @state |
| 59 | + when nil |
| 60 | + case |
| 61 | + when (text = @ss.scan(/has\([\s]*/)) |
| 62 | + action { [:HAS, text] } |
66 | 63 |
|
67 |
| - when (text = @ss.scan(/[-@]?([_A-Za-z]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*/)) |
68 |
| - action { [:IDENT, text] } |
| 64 | + when (text = @ss.scan(/[-@]?([_A-Za-z]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*\([\s]*/)) |
| 65 | + action { [:FUNCTION, text] } |
69 | 66 |
|
70 |
| - when (text = @ss.scan(/\#([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])+/)) |
71 |
| - action { [:HASH, text] } |
| 67 | + when (text = @ss.scan(/[-@]?([_A-Za-z]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*/)) |
| 68 | + action { [:IDENT, text] } |
72 | 69 |
|
73 |
| - when (text = @ss.scan(/[\s]*~=[\s]*/)) |
74 |
| - action { [:INCLUDES, text] } |
| 70 | + when (text = @ss.scan(/\#([_A-Za-z0-9-]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])+/)) |
| 71 | + action { [:HASH, text] } |
75 | 72 |
|
76 |
| - when (text = @ss.scan(/[\s]*\|=[\s]*/)) |
77 |
| - action { [:DASHMATCH, text] } |
| 73 | + when (text = @ss.scan(/[\s]*~=[\s]*/)) |
| 74 | + action { [:INCLUDES, text] } |
78 | 75 |
|
79 |
| - when (text = @ss.scan(/[\s]*\^=[\s]*/)) |
80 |
| - action { [:PREFIXMATCH, text] } |
| 76 | + when (text = @ss.scan(/[\s]*\|=[\s]*/)) |
| 77 | + action { [:DASHMATCH, text] } |
81 | 78 |
|
82 |
| - when (text = @ss.scan(/[\s]*\$=[\s]*/)) |
83 |
| - action { [:SUFFIXMATCH, text] } |
| 79 | + when (text = @ss.scan(/[\s]*\^=[\s]*/)) |
| 80 | + action { [:PREFIXMATCH, text] } |
84 | 81 |
|
85 |
| - when (text = @ss.scan(/[\s]*\*=[\s]*/)) |
86 |
| - action { [:SUBSTRINGMATCH, text] } |
| 82 | + when (text = @ss.scan(/[\s]*\$=[\s]*/)) |
| 83 | + action { [:SUFFIXMATCH, text] } |
87 | 84 |
|
88 |
| - when (text = @ss.scan(/[\s]*!=[\s]*/)) |
89 |
| - action { [:NOT_EQUAL, text] } |
| 85 | + when (text = @ss.scan(/[\s]*\*=[\s]*/)) |
| 86 | + action { [:SUBSTRINGMATCH, text] } |
90 | 87 |
|
91 |
| - when (text = @ss.scan(/[\s]*=[\s]*/)) |
92 |
| - action { [:EQUAL, text] } |
| 88 | + when (text = @ss.scan(/[\s]*!=[\s]*/)) |
| 89 | + action { [:NOT_EQUAL, text] } |
93 | 90 |
|
94 |
| - when (text = @ss.scan(/[\s]*\)/)) |
95 |
| - action { [:RPAREN, text] } |
| 91 | + when (text = @ss.scan(/[\s]*=[\s]*/)) |
| 92 | + action { [:EQUAL, text] } |
96 | 93 |
|
97 |
| - when (text = @ss.scan(/\[[\s]*/)) |
98 |
| - action { [:LSQUARE, text] } |
| 94 | + when (text = @ss.scan(/[\s]*\)/)) |
| 95 | + action { [:RPAREN, text] } |
99 | 96 |
|
100 |
| - when (text = @ss.scan(/[\s]*\]/)) |
101 |
| - action { [:RSQUARE, text] } |
| 97 | + when (text = @ss.scan(/\[[\s]*/)) |
| 98 | + action { [:LSQUARE, text] } |
102 | 99 |
|
103 |
| - when (text = @ss.scan(/[\s]*\+[\s]*/)) |
104 |
| - action { [:PLUS, text] } |
| 100 | + when (text = @ss.scan(/[\s]*\]/)) |
| 101 | + action { [:RSQUARE, text] } |
105 | 102 |
|
106 |
| - when (text = @ss.scan(/[\s]*>[\s]*/)) |
107 |
| - action { [:GREATER, text] } |
| 103 | + when (text = @ss.scan(/[\s]*\+[\s]*/)) |
| 104 | + action { [:PLUS, text] } |
108 | 105 |
|
109 |
| - when (text = @ss.scan(/[\s]*,[\s]*/)) |
110 |
| - action { [:COMMA, text] } |
| 106 | + when (text = @ss.scan(/[\s]*>[\s]*/)) |
| 107 | + action { [:GREATER, text] } |
111 | 108 |
|
112 |
| - when (text = @ss.scan(/[\s]*~[\s]*/)) |
113 |
| - action { [:TILDE, text] } |
| 109 | + when (text = @ss.scan(/[\s]*,[\s]*/)) |
| 110 | + action { [:COMMA, text] } |
114 | 111 |
|
115 |
| - when (text = @ss.scan(/\:not\([\s]*/)) |
116 |
| - action { [:NOT, text] } |
| 112 | + when (text = @ss.scan(/[\s]*~[\s]*/)) |
| 113 | + action { [:TILDE, text] } |
117 | 114 |
|
118 |
| - when (text = @ss.scan(/-?([0-9]+|[0-9]*\.[0-9]+)/)) |
119 |
| - action { [:NUMBER, text] } |
| 115 | + when (text = @ss.scan(/\:not\([\s]*/)) |
| 116 | + action { [:NOT, text] } |
120 | 117 |
|
121 |
| - when (text = @ss.scan(/[\s]*\/\/[\s]*/)) |
122 |
| - action { [:DOUBLESLASH, text] } |
| 118 | + when (text = @ss.scan(/-?([0-9]+|[0-9]*\.[0-9]+)/)) |
| 119 | + action { [:NUMBER, text] } |
123 | 120 |
|
124 |
| - when (text = @ss.scan(/[\s]*\/[\s]*/)) |
125 |
| - action { [:SLASH, text] } |
| 121 | + when (text = @ss.scan(/[\s]*\/\/[\s]*/)) |
| 122 | + action { [:DOUBLESLASH, text] } |
126 | 123 |
|
127 |
| - when (text = @ss.scan(/U\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})?/)) |
128 |
| - action {[:UNICODE_RANGE, text] } |
| 124 | + when (text = @ss.scan(/[\s]*\/[\s]*/)) |
| 125 | + action { [:SLASH, text] } |
129 | 126 |
|
130 |
| - when (text = @ss.scan(/[\s]+/)) |
131 |
| - action { [:S, text] } |
| 127 | + when (text = @ss.scan(/U\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})?/)) |
| 128 | + action {[:UNICODE_RANGE, text] } |
132 | 129 |
|
133 |
| - when (text = @ss.scan(/"([^\n\r\f"]|\n|\r\n|\r|\f|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*(?<!\\)(?:\\{2})*"|'([^\n\r\f']|\n|\r\n|\r|\f|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*(?<!\\)(?:\\{2})*'/)) |
134 |
| - action { [:STRING, text] } |
| 130 | + when (text = @ss.scan(/[\s]+/)) |
| 131 | + action { [:S, text] } |
135 | 132 |
|
136 |
| - when (text = @ss.scan(/./)) |
137 |
| - action { [text, text] } |
| 133 | + when (text = @ss.scan(/"([^\n\r\f"]|\n|\r\n|\r|\f|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*(?<!\\)(?:\\{2})*"|'([^\n\r\f']|\n|\r\n|\r|\f|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*(?<!\\)(?:\\{2})*'/)) |
| 134 | + action { [:STRING, text] } |
138 | 135 |
|
139 |
| - else |
140 |
| - text = @ss.string[@ss.pos .. -1] |
141 |
| - raise ScanError, "can not match: '" + text + "'" |
142 |
| - end # if |
| 136 | + when (text = @ss.scan(/./)) |
| 137 | + action { [text, text] } |
143 | 138 |
|
144 |
| - else |
145 |
| - raise ScanError, "undefined state: '" + state.to_s + "'" |
146 |
| - end # case state |
147 |
| - token |
148 |
| - end # def _next_token |
| 139 | + |
| 140 | + else |
| 141 | + text = @ss.string[@ss.pos .. -1] |
| 142 | + raise ScanError, "can not match: '" + text + "'" |
| 143 | + end # if |
| 144 | + |
| 145 | + else |
| 146 | + raise ScanError, "undefined state: '" + state.to_s + "'" |
| 147 | + end # case state |
| 148 | + token |
| 149 | + end # def _next_token |
149 | 150 |
|
150 | 151 | end # class
|
151 | 152 | end
|
|
0 commit comments