55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
# File 'lib/csspool/css/tokenizer.rb', line 55
def _next_token
text = @ss.peek(1)
@lineno += 1 if text == "\n"
token = case @state
when nil
case
when (text = @ss.scan(/url\([\s]*("([^\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])*"|'([^\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])*')[\s]*\)/i))
action { [:URI, st(text)] }
when (text = @ss.scan(/url\([\s]*([!#\$%&*-~]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*[\s]*\)/i))
action { [:URI, st(text)] }
when (text = @ss.scan(/U\+[0-9a-fA-F?]{1,6}(-[0-9a-fA-F]{1,6})?/i))
action {[:UNICODE_RANGE, st(text)] }
when (text = @ss.scan(/[\s]*\/\*(.|\s)*?\*\/[\s]*/i))
action { next_token }
when (text = @ss.scan(/not\([\s]*/i))
action { [:NOT_PSEUDO_CLASS, st(text)] }
when (text = @ss.scan(/(nth\-child|nth\-last\-child|nth\-of\-type|nth\-last\-of\-type)\([\s]*([\+\-]?[0-9]*n([\s]*[\+\-][\s]*[0-9]+)?|[\+\-]?[0-9]+|odd|even)[\s]*\)/i))
action { [:NTH_PSEUDO_CLASS, st(text)] }
when (text = @ss.scan(/(\-[A-Za-z]+\-)?(matches|any)\(\s*/i))
action { [:MATCHES_PSEUDO_CLASS, st(text)] }
when (text = @ss.scan(/(domain|url\-prefix)\([\s]*("([^\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])*"|'([^\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])*')[\s]*\)/i))
action { [:FUNCTION_NO_QUOTE, st(text)] }
when (text = @ss.scan(/(domain|url\-prefix)\([\s]*([!#\$%&*-~]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*[\s]*\)/i))
action { [:FUNCTION_NO_QUOTE, st(text)] }
when (text = @ss.scan(/(\-moz\-non\-element|\-moz\-anonymous\-block|\-moz\-anonymous\-positioned\-block|\-moz\-mathml\-anonymous\-block|\-moz\-xul\-anonymous\-block|\-moz\-hframeset\-border|\-moz\-vframeset\-border|\-moz\-line\-frame|\-moz\-button\-content|\-moz\-buttonlabel|\-moz\-cell\-content|\-moz\-dropdown\-list|\-moz\-fieldset\-content|\-moz\-frameset\-blank|\-moz\-display\-comboboxcontrol\-frame|\-moz\-html\-canvas\-content|\-moz\-inline\-table|\-moz\-table|\-moz\-table\-cell|\-moz\-table\-column\-group|\-moz\-table\-column|\-moz\-table\-outer|\-moz\-table\-row\-group|\-moz\-table\-row|\-moz\-canvas|\-moz\-pagebreak|\-moz\-page|\-moz\-pagecontent|\-moz\-page\-sequence|\-moz\-scrolled\-content|\-moz\-scrolled\-canvas|\-moz\-scrolled\-page\-sequence|\-moz\-column\-content|\-moz\-viewport|\-moz\-viewport\-scroll|\-moz\-anonymous\-flex\-item|\-moz\-tree\-column|\-moz\-tree\-row|\-moz\-tree\-separator|\-moz\-tree\-cell|\-moz\-tree\-indentation|\-moz\-tree\-line|\-moz\-tree\-twisty|\-moz\-tree\-image|\-moz\-tree\-cell\-text|\-moz\-tree\-checkbox|\-moz\-tree\-progressmeter|\-moz\-tree\-drop\-feedback|\-moz\-svg\-outer\-svg\-anon\-child|\-moz\-svg\-foreign\-content|\-moz\-svg\-text)\(/i))
action { [:MOZ_PSEUDO_ELEMENT, st(text)] }
when (text = @ss.scan(/[\s]*@media[\s]*/i))
action { @state = :LOGICQUERY; [:MEDIA_SYM, st(text)] }
when (text = @ss.scan(/[\s]*@supports[\s]*/i))
action { @state = :LOGICQUERY; [:SUPPORTS_SYM, st(text)] }
when (text = @ss.scan(/(\-[A-Za-z]+\-)?calc\(\s*/i))
action { [:CALC_SYM, st(text)] }
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*/i))
action { [:FUNCTION, st(text)] }
when (text = @ss.scan(/[\s]*@import[\s]*/i))
action { [:IMPORT_SYM, st(text)] }
when (text = @ss.scan(/[\s]*@page[\s]*/i))
action { [:PAGE_SYM, st(text)] }
when (text = @ss.scan(/[\s]*@charset[\s]*/i))
action { [:CHARSET_SYM, st(text)] }
when (text = @ss.scan(/[\s]*@(\-[A-Za-z]+\-)?document[\s]*/i))
action { [:DOCUMENT_QUERY_SYM, st(text)] }
when (text = @ss.scan(/[\s]*@namespace[\s]*/i))
action { [:NAMESPACE_SYM, st(text)] }
when (text = @ss.scan(/[\s]*@font\-face[\s]*/i))
action { [:FONTFACE_SYM, st(text)] }
when (text = @ss.scan(/[\s]*@(\-[A-Za-z]+\-)?keyframes[\s]*/i))
action { [:KEYFRAMES_SYM, st(text)] }
when (text = @ss.scan(/[\s]*!([\s]*|[\s]*\/\*(.|\s)*?\*\/[\s]*)important[\s]*/i))
action { [:IMPORTANT_SYM, st(text)] }
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])+/i))
action { [:VARIABLE_NAME, st(text)] }
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])*/i))
action { [:IDENT, st(text)] }
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])+/i))
action { [:HASH, st(text)] }
when (text = @ss.scan(/[\s]*~=[\s]*/i))
action { [:INCLUDES, st(text)] }
when (text = @ss.scan(/[\s]*\|=[\s]*/i))
action { [:DASHMATCH, st(text)] }
when (text = @ss.scan(/[\s]*\^=[\s]*/i))
action { [:PREFIXMATCH, st(text)] }
when (text = @ss.scan(/[\s]*\$=[\s]*/i))
action { [:SUFFIXMATCH, st(text)] }
when (text = @ss.scan(/[\s]*\*=[\s]*/i))
action { [:SUBSTRINGMATCH, st(text)] }
when (text = @ss.scan(/[\s]*!=[\s]*/i))
action { [:NOT_EQUAL, st(text)] }
when (text = @ss.scan(/[\s]*=[\s]*/i))
action { [:EQUAL, st(text)] }
when (text = @ss.scan(/[\s]*\)/i))
action { [:RPAREN, st(text)] }
when (text = @ss.scan(/[\s]*\(/i))
action { [:LPAREN, st(text)] }
when (text = @ss.scan(/\[[\s]*/i))
action { [:LSQUARE, st(text)] }
when (text = @ss.scan(/[\s]*\]/i))
action { [:RSQUARE, st(text)] }
when (text = @ss.scan(/[\s]*\+[\s]*/i))
action { [:PLUS, st(text)] }
when (text = @ss.scan(/[\s]*\{[\s]*/i))
action { [:LBRACE, st(text)] }
when (text = @ss.scan(/[\s]*\}[\s]*/i))
action { [:RBRACE, st(text)] }
when (text = @ss.scan(/[\s]*>[\s]*/i))
action { [:GREATER, st(text)] }
when (text = @ss.scan(/[\s]*,[\s]*/i))
action { [:COMMA, st(',')] }
when (text = @ss.scan(/[\s]*;[\s]*/i))
action { [:SEMI, st(';')] }
when (text = @ss.scan(/\:/i))
action { [:COLON, st(text)] }
when (text = @ss.scan(/\*/i))
action { [:STAR, st(text)] }
when (text = @ss.scan(/[\s]*~[\s]*/i))
action { [:TILDE, st(text)] }
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(px|cm|mm|in|pt|pc|mozmm|em|ex|ch|rem|vh|vw|vmin|vmax)[\s]*/i))
action { [:LENGTH, st(text)] }
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(deg|rad|grad)[\s]*/i))
action { [:ANGLE, st(text)] }
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(ms|s)[\s]*/i))
action { [:TIME, st(text)] }
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)[k]?hz[\s]*/i))
action { [:FREQ, st(text)] }
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)%[\s]*/i))
action { [:PERCENTAGE, st(text)] }
when (text = @ss.scan(/[\s]*[1-9][0-9]*[\s]*\/[\s]*[1-9][0-9]*[\s]*/i))
action { [:RATIO, st(text)] }
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)[\s]*/i))
action { [:NUMBER, st(text)] }
when (text = @ss.scan(/[\s]*\/\/[\s]*/i))
action { [:DOUBLESLASH, st(text)] }
when (text = @ss.scan(/[\s]*\/[\s]*/i))
action { [:SLASH, st('/')] }
when (text = @ss.scan(/<!--/i))
action { [:CDO, st(text)] }
when (text = @ss.scan(/-->/i))
action { [:CDC, st(text)] }
when (text = @ss.scan(/[\s]*\-(?!\-?([_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]*/i))
action { [:MINUS, st(text)] }
when (text = @ss.scan(/[\s]*\+[\s]*/i))
action { [:PLUS, st(text)] }
when (text = @ss.scan(/[\s]+/i))
action { [:S, st(text)] }
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])*"|'([^\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])*')/i))
action { [:STRING, st(text)] }
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])*|'([^\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])*)/i))
action { [:INVALID, st(text)] }
when (text = @ss.scan(/./i))
action { [st(text), st(text)] }
else
text = @ss.string[@ss.pos .. -1]
raise ScanError, "can not match: '" + text + "'"
end
when :LOGICQUERY
case
when (text = @ss.scan(/url\([\s]*("([^\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])*"|'([^\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])*')[\s]*\)/i))
action { [:URI, st(text)] }
when (text = @ss.scan(/url\([\s]*([!#\$%&*-~]|[^\0-\177]|\\[0-9A-Fa-f]{1,6}(\r\n|[\s])?|\\[^\n\r\f0-9A-Fa-f])*[\s]*\)/i))
action { [:URI, st(text)] }
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*/i))
action { [:FUNCTION, st(text)] }
when (text = @ss.scan(/[\s]*(and|only|not|or)[\s]+/i))
action { [text.upcase.strip.intern, st(text)] }
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(dpi|dpcm)/i))
action { [:RESOLUTION, st(text)]}
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(px|cm|mm|in|pt|pc|mozmm|em|ex|ch|rem|vh|vw|vmin|vmax)[\s]*/i))
action { [:LENGTH, st(text)] }
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(deg|rad|grad)[\s]*/i))
action { [:ANGLE, st(text)] }
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)(ms|s)[\s]*/i))
action { [:TIME, st(text)] }
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)[k]?hz[\s]*/i))
action { [:FREQ, st(text)] }
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)%[\s]*/i))
action { [:PERCENTAGE, st(text)] }
when (text = @ss.scan(/[\s]*[1-9][0-9]*[\s]*\/[\s]*[1-9][0-9]*[\s]*/i))
action { [:RATIO, st(text)] }
when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)[\s]*/i))
action { [:NUMBER, st(text)] }
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])*/i))
action { [:IDENT, st(text)] }
when (text = @ss.scan(/[\s]*,[\s]*/i))
action { [:COMMA, st(',')] }
when (text = @ss.scan(/[\s]*\)/i))
action { [:RPAREN, st(text)] }
when (text = @ss.scan(/[\s]*\(/i))
action { [:LPAREN, st(text)] }
when (text = @ss.scan(/\:/i))
action { [:COLON, st(text)] }
when (text = @ss.scan(/[\s]*!([\s]*|[\s]*\/\*(.|\s)*?\*\/[\s]*)important[\s]*/i))
action { [:IMPORTANT_SYM, st(text)] }
when (text = @ss.scan(/[\s]*\{[\s]*/i))
action { @state = nil; [:LBRACE, st(text)] }
when (text = @ss.scan(/[\s]+/i))
action { [:S, st(text)] }
else
text = @ss.string[@ss.pos .. -1]
raise ScanError, "can not match: '" + text + "'"
end
else
raise ScanError, "undefined state: '" + state.to_s + "'"
end token
end
|