Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(550)

Side by Side Diff: csslib/lib/src/tokenkind.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « csslib/lib/src/tokenizer_base.dart ('k') | csslib/lib/src/tree.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of csslib.parser;
6
7 // TODO(terry): Need to be consistent with tokens either they're ASCII tokens
8 // e.g., ASTERISK or they're CSS e.g., PSEUDO, COMBINATOR_*.
9 class TokenKind {
10 // Common shared tokens used in TokenizerBase.
11 static const int UNUSED = 0; // Unused place holder...
12 static const int END_OF_FILE = 1; // EOF
13 static const int LPAREN = 2; // (
14 static const int RPAREN = 3; // )
15 static const int LBRACK = 4; // [
16 static const int RBRACK = 5; // ]
17 static const int LBRACE = 6; // {
18 static const int RBRACE = 7; // }
19 static const int DOT = 8; // .
20 static const int SEMICOLON = 9; // ;
21
22 // Unique tokens for CSS.
23 static const int AT = 10; // @
24 static const int HASH = 11; // #
25 static const int PLUS = 12; // +
26 static const int GREATER = 13; // >
27 static const int TILDE = 14; // ~
28 static const int ASTERISK = 15; // *
29 static const int NAMESPACE = 16; // |
30 static const int COLON = 17; // :
31 static const int PRIVATE_NAME = 18; // _ prefix private class or id
32 static const int COMMA = 19; // ,
33 static const int SPACE = 20;
34 static const int TAB = 21; // /t
35 static const int NEWLINE = 22; // /n
36 static const int RETURN = 23; // /r
37 static const int PERCENT = 24; // %
38 static const int SINGLE_QUOTE = 25; // '
39 static const int DOUBLE_QUOTE = 26; // "
40 static const int SLASH = 27; // /
41 static const int EQUALS = 28; // =
42 static const int CARET = 30; // ^
43 static const int DOLLAR = 31; // $
44 static const int LESS = 32; // <
45 static const int BANG = 33; // !
46 static const int MINUS = 34; // -
47 static const int BACKSLASH = 35; // \
48 static const int AMPERSAND = 36; // &
49
50 // WARNING: Tokens from this point and above must have the corresponding ASCII
51 // character in the TokenChar list at the bottom of this file. The
52 // order of the above tokens should be the same order as TokenChar.
53
54 /** [TokenKind] representing integer tokens. */
55 static const int INTEGER = 60;
56
57 /** [TokenKind] representing hex integer tokens. */
58 static const int HEX_INTEGER = 61;
59
60 /** [TokenKind] representing double tokens. */
61 static const int DOUBLE = 62;
62
63 /** [TokenKind] representing whitespace tokens. */
64 static const int WHITESPACE = 63;
65
66 /** [TokenKind] representing comment tokens. */
67 static const int COMMENT = 64;
68
69 /** [TokenKind] representing error tokens. */
70 static const int ERROR = 65;
71
72 /** [TokenKind] representing incomplete string tokens. */
73 static const int INCOMPLETE_STRING = 66;
74
75 /** [TokenKind] representing incomplete comment tokens. */
76 static const int INCOMPLETE_COMMENT = 67;
77
78 static const int VAR_DEFINITION = 400; // var-NNN-NNN
79 static const int VAR_USAGE = 401; // var(NNN-NNN [,default])
80
81 // Synthesized Tokens (no character associated with TOKEN).
82 static const int STRING = 500;
83 static const int STRING_PART = 501;
84 static const int NUMBER = 502;
85 static const int HEX_NUMBER = 503;
86 static const int HTML_COMMENT = 504; // <!--
87 static const int IMPORTANT = 505; // !important
88 static const int CDATA_START = 506; // <![CDATA[
89 static const int CDATA_END = 507; // ]]>
90 // U+uNumber[-U+uNumber]
91 // uNumber = 0..10FFFF | ?[?]*
92 static const int UNICODE_RANGE = 508;
93 static const int HEX_RANGE = 509; // ? in the hex range
94 static const int IDENTIFIER = 511;
95
96 // Uniquely synthesized tokens for CSS.
97 static const int SELECTOR_EXPRESSION = 512;
98 static const int COMBINATOR_NONE = 513;
99 static const int COMBINATOR_DESCENDANT = 514; // Space combinator
100 static const int COMBINATOR_PLUS = 515; // + combinator
101 static const int COMBINATOR_GREATER = 516; // > combinator
102 static const int COMBINATOR_TILDE = 517; // ~ combinator
103
104 static const int UNARY_OP_NONE = 518; // No unary operator present.
105
106 // Attribute match types:
107 static const int INCLUDES = 530; // '~='
108 static const int DASH_MATCH = 531; // '|='
109 static const int PREFIX_MATCH = 532; // '^='
110 static const int SUFFIX_MATCH = 533; // '$='
111 static const int SUBSTRING_MATCH = 534; // '*='
112 static const int NO_MATCH = 535; // No operator.
113
114 // Unit types:
115 static const int UNIT_EM = 600;
116 static const int UNIT_EX = 601;
117 static const int UNIT_LENGTH_PX = 602;
118 static const int UNIT_LENGTH_CM = 603;
119 static const int UNIT_LENGTH_MM = 604;
120 static const int UNIT_LENGTH_IN = 605;
121 static const int UNIT_LENGTH_PT = 606;
122 static const int UNIT_LENGTH_PC = 607;
123 static const int UNIT_ANGLE_DEG = 608;
124 static const int UNIT_ANGLE_RAD = 609;
125 static const int UNIT_ANGLE_GRAD = 610;
126 static const int UNIT_ANGLE_TURN = 611;
127 static const int UNIT_TIME_MS = 612;
128 static const int UNIT_TIME_S = 613;
129 static const int UNIT_FREQ_HZ = 614;
130 static const int UNIT_FREQ_KHZ = 615;
131 static const int UNIT_PERCENT = 616;
132 static const int UNIT_FRACTION = 617;
133 static const int UNIT_RESOLUTION_DPI = 618;
134 static const int UNIT_RESOLUTION_DPCM = 619;
135 static const int UNIT_RESOLUTION_DPPX = 620;
136 static const int UNIT_CH = 621; // Measure of "0" U+0030 glyph.
137 static const int UNIT_REM = 622; // computed value ‘font-size’ on root elem.
138 static const int UNIT_VIEWPORT_VW = 623;
139 static const int UNIT_VIEWPORT_VH = 624;
140 static const int UNIT_VIEWPORT_VMIN = 625;
141 static const int UNIT_VIEWPORT_VMAX = 626;
142
143 // Directives (@nnnn)
144 static const int DIRECTIVE_NONE = 640;
145 static const int DIRECTIVE_IMPORT = 641;
146 static const int DIRECTIVE_MEDIA = 642;
147 static const int DIRECTIVE_PAGE = 643;
148 static const int DIRECTIVE_CHARSET = 644;
149 static const int DIRECTIVE_STYLET = 645;
150 static const int DIRECTIVE_KEYFRAMES = 646;
151 static const int DIRECTIVE_WEB_KIT_KEYFRAMES = 647;
152 static const int DIRECTIVE_MOZ_KEYFRAMES = 648;
153 static const int DIRECTIVE_MS_KEYFRAMES = 649;
154 static const int DIRECTIVE_O_KEYFRAMES = 650;
155 static const int DIRECTIVE_FONTFACE = 651;
156 static const int DIRECTIVE_NAMESPACE = 652;
157 static const int DIRECTIVE_HOST = 653;
158 static const int DIRECTIVE_MIXIN = 654;
159 static const int DIRECTIVE_INCLUDE = 655;
160 static const int DIRECTIVE_CONTENT = 656;
161 static const int DIRECTIVE_EXTEND = 657;
162
163 // Media query operators
164 static const int MEDIA_OP_ONLY = 665; // Unary.
165 static const int MEDIA_OP_NOT = 666; // Unary.
166 static const int MEDIA_OP_AND = 667; // Binary.
167
168 // Directives inside of a @page (margin sym).
169 static const int MARGIN_DIRECTIVE_TOPLEFTCORNER = 670;
170 static const int MARGIN_DIRECTIVE_TOPLEFT = 671;
171 static const int MARGIN_DIRECTIVE_TOPCENTER = 672;
172 static const int MARGIN_DIRECTIVE_TOPRIGHT = 673;
173 static const int MARGIN_DIRECTIVE_TOPRIGHTCORNER = 674;
174 static const int MARGIN_DIRECTIVE_BOTTOMLEFTCORNER = 675;
175 static const int MARGIN_DIRECTIVE_BOTTOMLEFT = 676;
176 static const int MARGIN_DIRECTIVE_BOTTOMCENTER = 677;
177 static const int MARGIN_DIRECTIVE_BOTTOMRIGHT = 678;
178 static const int MARGIN_DIRECTIVE_BOTTOMRIGHTCORNER = 679;
179 static const int MARGIN_DIRECTIVE_LEFTTOP = 680;
180 static const int MARGIN_DIRECTIVE_LEFTMIDDLE = 681;
181 static const int MARGIN_DIRECTIVE_LEFTBOTTOM = 682;
182 static const int MARGIN_DIRECTIVE_RIGHTTOP = 683;
183 static const int MARGIN_DIRECTIVE_RIGHTMIDDLE = 684;
184 static const int MARGIN_DIRECTIVE_RIGHTBOTTOM = 685;
185
186 // Simple selector type.
187 static const int CLASS_NAME = 700; // .class
188 static const int ELEMENT_NAME = 701; // tagName
189 static const int HASH_NAME = 702; // #elementId
190 static const int ATTRIBUTE_NAME = 703; // [attrib]
191 static const int PSEUDO_ELEMENT_NAME = 704; // ::pseudoElement
192 static const int PSEUDO_CLASS_NAME = 705; // :pseudoClass
193 static const int NEGATION = 706; // NOT
194
195 static const List<Map<int, String>> _DIRECTIVES = const [
196 const {'type': TokenKind.DIRECTIVE_IMPORT, 'value': 'import'},
197 const {'type': TokenKind.DIRECTIVE_MEDIA, 'value': 'media'},
198 const {'type': TokenKind.DIRECTIVE_PAGE, 'value': 'page'},
199 const {'type': TokenKind.DIRECTIVE_CHARSET, 'value': 'charset'},
200 const {'type': TokenKind.DIRECTIVE_STYLET, 'value': 'stylet'},
201 const {'type': TokenKind.DIRECTIVE_KEYFRAMES, 'value': 'keyframes'},
202 const {
203 'type': TokenKind.DIRECTIVE_WEB_KIT_KEYFRAMES,
204 'value': '-webkit-keyframes'
205 },
206 const {
207 'type': TokenKind.DIRECTIVE_MOZ_KEYFRAMES,
208 'value': '-moz-keyframes'
209 },
210 const {'type': TokenKind.DIRECTIVE_MS_KEYFRAMES, 'value': '-ms-keyframes'},
211 const {'type': TokenKind.DIRECTIVE_O_KEYFRAMES, 'value': '-o-keyframes'},
212 const {'type': TokenKind.DIRECTIVE_FONTFACE, 'value': 'font-face'},
213 const {'type': TokenKind.DIRECTIVE_NAMESPACE, 'value': 'namespace'},
214 const {'type': TokenKind.DIRECTIVE_HOST, 'value': 'host'},
215 const {'type': TokenKind.DIRECTIVE_MIXIN, 'value': 'mixin'},
216 const {'type': TokenKind.DIRECTIVE_INCLUDE, 'value': 'include'},
217 const {'type': TokenKind.DIRECTIVE_CONTENT, 'value': 'content'},
218 const {'type': TokenKind.DIRECTIVE_EXTEND, 'value': 'extend'},
219 ];
220
221 static const List<Map<int, String>> MEDIA_OPERATORS = const [
222 const {'type': TokenKind.MEDIA_OP_ONLY, 'value': 'only'},
223 const {'type': TokenKind.MEDIA_OP_NOT, 'value': 'not'},
224 const {'type': TokenKind.MEDIA_OP_AND, 'value': 'and'},
225 ];
226
227 static const List<Map<int, String>> MARGIN_DIRECTIVES = const [
228 const {
229 'type': TokenKind.MARGIN_DIRECTIVE_TOPLEFTCORNER,
230 'value': 'top-left-corner'
231 },
232 const {'type': TokenKind.MARGIN_DIRECTIVE_TOPLEFT, 'value': 'top-left'},
233 const {'type': TokenKind.MARGIN_DIRECTIVE_TOPCENTER, 'value': 'top-center'},
234 const {'type': TokenKind.MARGIN_DIRECTIVE_TOPRIGHT, 'value': 'top-right'},
235 const {
236 'type': TokenKind.MARGIN_DIRECTIVE_TOPRIGHTCORNER,
237 'value': 'top-right-corner'
238 },
239 const {
240 'type': TokenKind.MARGIN_DIRECTIVE_BOTTOMLEFTCORNER,
241 'value': 'bottom-left-corner'
242 },
243 const {
244 'type': TokenKind.MARGIN_DIRECTIVE_BOTTOMLEFT,
245 'value': 'bottom-left'
246 },
247 const {
248 'type': TokenKind.MARGIN_DIRECTIVE_BOTTOMCENTER,
249 'value': 'bottom-center'
250 },
251 const {
252 'type': TokenKind.MARGIN_DIRECTIVE_BOTTOMRIGHT,
253 'value': 'bottom-right'
254 },
255 const {
256 'type': TokenKind.MARGIN_DIRECTIVE_BOTTOMRIGHTCORNER,
257 'value': 'bottom-right-corner'
258 },
259 const {'type': TokenKind.MARGIN_DIRECTIVE_LEFTTOP, 'value': 'left-top'},
260 const {
261 'type': TokenKind.MARGIN_DIRECTIVE_LEFTMIDDLE,
262 'value': 'left-middle'
263 },
264 const {
265 'type': TokenKind.MARGIN_DIRECTIVE_LEFTBOTTOM,
266 'value': 'right-bottom'
267 },
268 const {'type': TokenKind.MARGIN_DIRECTIVE_RIGHTTOP, 'value': 'right-top'},
269 const {
270 'type': TokenKind.MARGIN_DIRECTIVE_RIGHTMIDDLE,
271 'value': 'right-middle'
272 },
273 const {
274 'type': TokenKind.MARGIN_DIRECTIVE_RIGHTBOTTOM,
275 'value': 'right-bottom'
276 },
277 ];
278
279 static const List<Map> _UNITS = const [
280 const {'unit': TokenKind.UNIT_EM, 'value': 'em'},
281 const {'unit': TokenKind.UNIT_EX, 'value': 'ex'},
282 const {'unit': TokenKind.UNIT_LENGTH_PX, 'value': 'px'},
283 const {'unit': TokenKind.UNIT_LENGTH_CM, 'value': 'cm'},
284 const {'unit': TokenKind.UNIT_LENGTH_MM, 'value': 'mm'},
285 const {'unit': TokenKind.UNIT_LENGTH_IN, 'value': 'in'},
286 const {'unit': TokenKind.UNIT_LENGTH_PT, 'value': 'pt'},
287 const {'unit': TokenKind.UNIT_LENGTH_PC, 'value': 'pc'},
288 const {'unit': TokenKind.UNIT_ANGLE_DEG, 'value': 'deg'},
289 const {'unit': TokenKind.UNIT_ANGLE_RAD, 'value': 'rad'},
290 const {'unit': TokenKind.UNIT_ANGLE_GRAD, 'value': 'grad'},
291 const {'unit': TokenKind.UNIT_ANGLE_TURN, 'value': 'turn'},
292 const {'unit': TokenKind.UNIT_TIME_MS, 'value': 'ms'},
293 const {'unit': TokenKind.UNIT_TIME_S, 'value': 's'},
294 const {'unit': TokenKind.UNIT_FREQ_HZ, 'value': 'hz'},
295 const {'unit': TokenKind.UNIT_FREQ_KHZ, 'value': 'khz'},
296 const {'unit': TokenKind.UNIT_FRACTION, 'value': 'fr'},
297 const {'unit': TokenKind.UNIT_RESOLUTION_DPI, 'value': 'dpi'},
298 const {'unit': TokenKind.UNIT_RESOLUTION_DPCM, 'value': 'dpcm'},
299 const {'unit': TokenKind.UNIT_RESOLUTION_DPPX, 'value': 'dppx'},
300 const {'unit': TokenKind.UNIT_CH, 'value': 'ch'},
301 const {'unit': TokenKind.UNIT_REM, 'value': 'rem'},
302 const {'unit': TokenKind.UNIT_VIEWPORT_VW, 'value': 'vw'},
303 const {'unit': TokenKind.UNIT_VIEWPORT_VH, 'value': 'vh'},
304 const {'unit': TokenKind.UNIT_VIEWPORT_VMIN, 'value': 'vmin'},
305 const {'unit': TokenKind.UNIT_VIEWPORT_VMAX, 'value': 'vmax'},
306 ];
307
308 // Some more constants:
309 static const int ASCII_UPPER_A = 65; // ASCII value for uppercase A
310 static const int ASCII_UPPER_Z = 90; // ASCII value for uppercase Z
311
312 // Extended color keywords:
313 static const List<Map> _EXTENDED_COLOR_NAMES = const [
314 const {'name': 'aliceblue', 'value': 0xF08FF},
315 const {'name': 'antiquewhite', 'value': 0xFAEBD7},
316 const {'name': 'aqua', 'value': 0x00FFFF},
317 const {'name': 'aquamarine', 'value': 0x7FFFD4},
318 const {'name': 'azure', 'value': 0xF0FFFF},
319 const {'name': 'beige', 'value': 0xF5F5DC},
320 const {'name': 'bisque', 'value': 0xFFE4C4},
321 const {'name': 'black', 'value': 0x000000},
322 const {'name': 'blanchedalmond', 'value': 0xFFEBCD},
323 const {'name': 'blue', 'value': 0x0000FF},
324 const {'name': 'blueviolet', 'value': 0x8A2BE2},
325 const {'name': 'brown', 'value': 0xA52A2A},
326 const {'name': 'burlywood', 'value': 0xDEB887},
327 const {'name': 'cadetblue', 'value': 0x5F9EA0},
328 const {'name': 'chartreuse', 'value': 0x7FFF00},
329 const {'name': 'chocolate', 'value': 0xD2691E},
330 const {'name': 'coral', 'value': 0xFF7F50},
331 const {'name': 'cornflowerblue', 'value': 0x6495ED},
332 const {'name': 'cornsilk', 'value': 0xFFF8DC},
333 const {'name': 'crimson', 'value': 0xDC143C},
334 const {'name': 'cyan', 'value': 0x00FFFF},
335 const {'name': 'darkblue', 'value': 0x00008B},
336 const {'name': 'darkcyan', 'value': 0x008B8B},
337 const {'name': 'darkgoldenrod', 'value': 0xB8860B},
338 const {'name': 'darkgray', 'value': 0xA9A9A9},
339 const {'name': 'darkgreen', 'value': 0x006400},
340 const {'name': 'darkgrey', 'value': 0xA9A9A9},
341 const {'name': 'darkkhaki', 'value': 0xBDB76B},
342 const {'name': 'darkmagenta', 'value': 0x8B008B},
343 const {'name': 'darkolivegreen', 'value': 0x556B2F},
344 const {'name': 'darkorange', 'value': 0xFF8C00},
345 const {'name': 'darkorchid', 'value': 0x9932CC},
346 const {'name': 'darkred', 'value': 0x8B0000},
347 const {'name': 'darksalmon', 'value': 0xE9967A},
348 const {'name': 'darkseagreen', 'value': 0x8FBC8F},
349 const {'name': 'darkslateblue', 'value': 0x483D8B},
350 const {'name': 'darkslategray', 'value': 0x2F4F4F},
351 const {'name': 'darkslategrey', 'value': 0x2F4F4F},
352 const {'name': 'darkturquoise', 'value': 0x00CED1},
353 const {'name': 'darkviolet', 'value': 0x9400D3},
354 const {'name': 'deeppink', 'value': 0xFF1493},
355 const {'name': 'deepskyblue', 'value': 0x00BFFF},
356 const {'name': 'dimgray', 'value': 0x696969},
357 const {'name': 'dimgrey', 'value': 0x696969},
358 const {'name': 'dodgerblue', 'value': 0x1E90FF},
359 const {'name': 'firebrick', 'value': 0xB22222},
360 const {'name': 'floralwhite', 'value': 0xFFFAF0},
361 const {'name': 'forestgreen', 'value': 0x228B22},
362 const {'name': 'fuchsia', 'value': 0xFF00FF},
363 const {'name': 'gainsboro', 'value': 0xDCDCDC},
364 const {'name': 'ghostwhite', 'value': 0xF8F8FF},
365 const {'name': 'gold', 'value': 0xFFD700},
366 const {'name': 'goldenrod', 'value': 0xDAA520},
367 const {'name': 'gray', 'value': 0x808080},
368 const {'name': 'green', 'value': 0x008000},
369 const {'name': 'greenyellow', 'value': 0xADFF2F},
370 const {'name': 'grey', 'value': 0x808080},
371 const {'name': 'honeydew', 'value': 0xF0FFF0},
372 const {'name': 'hotpink', 'value': 0xFF69B4},
373 const {'name': 'indianred', 'value': 0xCD5C5C},
374 const {'name': 'indigo', 'value': 0x4B0082},
375 const {'name': 'ivory', 'value': 0xFFFFF0},
376 const {'name': 'khaki', 'value': 0xF0E68C},
377 const {'name': 'lavender', 'value': 0xE6E6FA},
378 const {'name': 'lavenderblush', 'value': 0xFFF0F5},
379 const {'name': 'lawngreen', 'value': 0x7CFC00},
380 const {'name': 'lemonchiffon', 'value': 0xFFFACD},
381 const {'name': 'lightblue', 'value': 0xADD8E6},
382 const {'name': 'lightcoral', 'value': 0xF08080},
383 const {'name': 'lightcyan', 'value': 0xE0FFFF},
384 const {'name': 'lightgoldenrodyellow', 'value': 0xFAFAD2},
385 const {'name': 'lightgray', 'value': 0xD3D3D3},
386 const {'name': 'lightgreen', 'value': 0x90EE90},
387 const {'name': 'lightgrey', 'value': 0xD3D3D3},
388 const {'name': 'lightpink', 'value': 0xFFB6C1},
389 const {'name': 'lightsalmon', 'value': 0xFFA07A},
390 const {'name': 'lightseagreen', 'value': 0x20B2AA},
391 const {'name': 'lightskyblue', 'value': 0x87CEFA},
392 const {'name': 'lightslategray', 'value': 0x778899},
393 const {'name': 'lightslategrey', 'value': 0x778899},
394 const {'name': 'lightsteelblue', 'value': 0xB0C4DE},
395 const {'name': 'lightyellow', 'value': 0xFFFFE0},
396 const {'name': 'lime', 'value': 0x00FF00},
397 const {'name': 'limegreen', 'value': 0x32CD32},
398 const {'name': 'linen', 'value': 0xFAF0E6},
399 const {'name': 'magenta', 'value': 0xFF00FF},
400 const {'name': 'maroon', 'value': 0x800000},
401 const {'name': 'mediumaquamarine', 'value': 0x66CDAA},
402 const {'name': 'mediumblue', 'value': 0x0000CD},
403 const {'name': 'mediumorchid', 'value': 0xBA55D3},
404 const {'name': 'mediumpurple', 'value': 0x9370DB},
405 const {'name': 'mediumseagreen', 'value': 0x3CB371},
406 const {'name': 'mediumslateblue', 'value': 0x7B68EE},
407 const {'name': 'mediumspringgreen', 'value': 0x00FA9A},
408 const {'name': 'mediumturquoise', 'value': 0x48D1CC},
409 const {'name': 'mediumvioletred', 'value': 0xC71585},
410 const {'name': 'midnightblue', 'value': 0x191970},
411 const {'name': 'mintcream', 'value': 0xF5FFFA},
412 const {'name': 'mistyrose', 'value': 0xFFE4E1},
413 const {'name': 'moccasin', 'value': 0xFFE4B5},
414 const {'name': 'navajowhite', 'value': 0xFFDEAD},
415 const {'name': 'navy', 'value': 0x000080},
416 const {'name': 'oldlace', 'value': 0xFDF5E6},
417 const {'name': 'olive', 'value': 0x808000},
418 const {'name': 'olivedrab', 'value': 0x6B8E23},
419 const {'name': 'orange', 'value': 0xFFA500},
420 const {'name': 'orangered', 'value': 0xFF4500},
421 const {'name': 'orchid', 'value': 0xDA70D6},
422 const {'name': 'palegoldenrod', 'value': 0xEEE8AA},
423 const {'name': 'palegreen', 'value': 0x98FB98},
424 const {'name': 'paleturquoise', 'value': 0xAFEEEE},
425 const {'name': 'palevioletred', 'value': 0xDB7093},
426 const {'name': 'papayawhip', 'value': 0xFFEFD5},
427 const {'name': 'peachpuff', 'value': 0xFFDAB9},
428 const {'name': 'peru', 'value': 0xCD853F},
429 const {'name': 'pink', 'value': 0xFFC0CB},
430 const {'name': 'plum', 'value': 0xDDA0DD},
431 const {'name': 'powderblue', 'value': 0xB0E0E6},
432 const {'name': 'purple', 'value': 0x800080},
433 const {'name': 'red', 'value': 0xFF0000},
434 const {'name': 'rosybrown', 'value': 0xBC8F8F},
435 const {'name': 'royalblue', 'value': 0x4169E1},
436 const {'name': 'saddlebrown', 'value': 0x8B4513},
437 const {'name': 'salmon', 'value': 0xFA8072},
438 const {'name': 'sandybrown', 'value': 0xF4A460},
439 const {'name': 'seagreen', 'value': 0x2E8B57},
440 const {'name': 'seashell', 'value': 0xFFF5EE},
441 const {'name': 'sienna', 'value': 0xA0522D},
442 const {'name': 'silver', 'value': 0xC0C0C0},
443 const {'name': 'skyblue', 'value': 0x87CEEB},
444 const {'name': 'slateblue', 'value': 0x6A5ACD},
445 const {'name': 'slategray', 'value': 0x708090},
446 const {'name': 'slategrey', 'value': 0x708090},
447 const {'name': 'snow', 'value': 0xFFFAFA},
448 const {'name': 'springgreen', 'value': 0x00FF7F},
449 const {'name': 'steelblue', 'value': 0x4682B4},
450 const {'name': 'tan', 'value': 0xD2B48C},
451 const {'name': 'teal', 'value': 0x008080},
452 const {'name': 'thistle', 'value': 0xD8BFD8},
453 const {'name': 'tomato', 'value': 0xFF6347},
454 const {'name': 'turquoise', 'value': 0x40E0D0},
455 const {'name': 'violet', 'value': 0xEE82EE},
456 const {'name': 'wheat', 'value': 0xF5DEB3},
457 const {'name': 'white', 'value': 0xFFFFFF},
458 const {'name': 'whitesmoke', 'value': 0xF5F5F5},
459 const {'name': 'yellow', 'value': 0xFFFF00},
460 const {'name': 'yellowgreen', 'value': 0x9ACD32},
461 ];
462
463 // TODO(terry): Should used Dart mirroring for parameter values and types
464 // especially for enumeration (e.g., counter's second parameter
465 // is list-style-type which is an enumerated list for ordering
466 // of a list 'circle', 'decimal', 'lower-roman', 'square', etc.
467 // see http://www.w3schools.com/cssref/pr_list-style-type.asp
468 // for list of possible values.
469
470 /**
471 * Check if name is a pre-defined CSS name. Used by error handler to report
472 * if name is unknown or used improperly.
473 */
474 static bool isPredefinedName(String name) {
475 var nameLen = name.length;
476 // TODO(terry): Add more pre-defined names (hidden, bolder, inherit, etc.).
477 if (matchUnits(name, 0, nameLen) == -1 ||
478 matchDirectives(name, 0, nameLen) == -1 ||
479 matchMarginDirectives(name, 0, nameLen) == -1 ||
480 matchColorName(name) == null) {
481 return false;
482 }
483
484 return true;
485 }
486
487 /** Return the token that matches the unit ident found. */
488 static int matchList(
489 var identList, String tokenField, String text, int offset, int length) {
490 for (final entry in identList) {
491 String ident = entry['value'];
492
493 if (length == ident.length) {
494 int idx = offset;
495 bool match = true;
496 for (int i = 0; i < ident.length; i++) {
497 int identChar = ident.codeUnitAt(i);
498 int char = text.codeUnitAt(idx++);
499 // Compare lowercase to lowercase then check if char is uppercase.
500 match = match &&
501 (char == identChar ||
502 ((char >= ASCII_UPPER_A && char <= ASCII_UPPER_Z) &&
503 (char + 32) == identChar));
504 if (!match) {
505 break;
506 }
507 }
508
509 if (match) {
510 // Completely matched; return the token for this unit.
511 return entry[tokenField];
512 }
513 }
514 }
515
516 return -1; // Not a unit token.
517 }
518
519 /** Return the token that matches the unit ident found. */
520 static int matchUnits(String text, int offset, int length) {
521 return matchList(_UNITS, 'unit', text, offset, length);
522 }
523
524 /** Return the token that matches the directive name found. */
525 static int matchDirectives(String text, int offset, int length) {
526 return matchList(_DIRECTIVES, 'type', text, offset, length);
527 }
528
529 /** Return the token that matches the margin directive name found. */
530 static int matchMarginDirectives(String text, int offset, int length) {
531 return matchList(MARGIN_DIRECTIVES, 'type', text, offset, length);
532 }
533
534 /** Return the token that matches the media operator found. */
535 static int matchMediaOperator(String text, int offset, int length) {
536 return matchList(MEDIA_OPERATORS, 'type', text, offset, length);
537 }
538
539 static String idToValue(var identList, int tokenId) {
540 for (var entry in identList) {
541 if (tokenId == entry['type']) {
542 return entry['value'];
543 }
544 }
545
546 return null;
547 }
548
549 /** Return the unit token as its pretty name. */
550 static String unitToString(int unitTokenToFind) {
551 if (unitTokenToFind == TokenKind.PERCENT) {
552 return '%';
553 } else {
554 for (final entry in _UNITS) {
555 int unit = entry['unit'];
556 if (unit == unitTokenToFind) {
557 return entry['value'];
558 }
559 }
560 }
561
562 return '<BAD UNIT>'; // Not a unit token.
563 }
564
565 /**
566 * Match color name, case insensitive match and return the associated color
567 * entry from _EXTENDED_COLOR_NAMES list, return [:null:] if not found.
568 */
569 static Map matchColorName(String text) {
570 var name = text.toLowerCase();
571 return _EXTENDED_COLOR_NAMES.firstWhere((e) => e['name'] == name,
572 orElse: () => null);
573 }
574
575 /** Return RGB value as [int] from a color entry in _EXTENDED_COLOR_NAMES. */
576 static int colorValue(Map entry) {
577 assert(entry != null);
578 return entry['value'];
579 }
580
581 static String hexToColorName(hexValue) {
582 for (final entry in _EXTENDED_COLOR_NAMES) {
583 if (entry['value'] == hexValue) {
584 return entry['name'];
585 }
586 }
587
588 return null;
589 }
590
591 static String decimalToHex(int number, [int minDigits = 1]) {
592 final String _HEX_DIGITS = '0123456789abcdef';
593
594 List<String> result = new List<String>();
595
596 int dividend = number >> 4;
597 int remain = number % 16;
598 result.add(_HEX_DIGITS[remain]);
599 while (dividend != 0) {
600 remain = dividend % 16;
601 dividend >>= 4;
602 result.add(_HEX_DIGITS[remain]);
603 }
604
605 StringBuffer invertResult = new StringBuffer();
606 int paddings = minDigits - result.length;
607 while (paddings-- > 0) {
608 invertResult.write('0');
609 }
610 for (int i = result.length - 1; i >= 0; i--) {
611 invertResult.write(result[i]);
612 }
613
614 return invertResult.toString();
615 }
616
617 static String kindToString(int kind) {
618 switch (kind) {
619 case TokenKind.UNUSED:
620 return "ERROR";
621 case TokenKind.END_OF_FILE:
622 return "end of file";
623 case TokenKind.LPAREN:
624 return "(";
625 case TokenKind.RPAREN:
626 return ")";
627 case TokenKind.LBRACK:
628 return "[";
629 case TokenKind.RBRACK:
630 return "]";
631 case TokenKind.LBRACE:
632 return "{";
633 case TokenKind.RBRACE:
634 return "}";
635 case TokenKind.DOT:
636 return ".";
637 case TokenKind.SEMICOLON:
638 return ";";
639 case TokenKind.AT:
640 return "@";
641 case TokenKind.HASH:
642 return "#";
643 case TokenKind.PLUS:
644 return "+";
645 case TokenKind.GREATER:
646 return ">";
647 case TokenKind.TILDE:
648 return "~";
649 case TokenKind.ASTERISK:
650 return "*";
651 case TokenKind.NAMESPACE:
652 return "|";
653 case TokenKind.COLON:
654 return ":";
655 case TokenKind.PRIVATE_NAME:
656 return "_";
657 case TokenKind.COMMA:
658 return ",";
659 case TokenKind.SPACE:
660 return " ";
661 case TokenKind.TAB:
662 return "\t";
663 case TokenKind.NEWLINE:
664 return "\n";
665 case TokenKind.RETURN:
666 return "\r";
667 case TokenKind.PERCENT:
668 return "%";
669 case TokenKind.SINGLE_QUOTE:
670 return "'";
671 case TokenKind.DOUBLE_QUOTE:
672 return "\"";
673 case TokenKind.SLASH:
674 return "/";
675 case TokenKind.EQUALS:
676 return '=';
677 case TokenKind.CARET:
678 return '^';
679 case TokenKind.DOLLAR:
680 return '\$';
681 case TokenKind.LESS:
682 return '<';
683 case TokenKind.BANG:
684 return '!';
685 case TokenKind.MINUS:
686 return '-';
687 case TokenKind.BACKSLASH:
688 return '\\';
689 default:
690 throw "Unknown TOKEN";
691 }
692 }
693
694 static bool isKindIdentifier(int kind) {
695 switch (kind) {
696 // Synthesized tokens.
697 case TokenKind.DIRECTIVE_IMPORT:
698 case TokenKind.DIRECTIVE_MEDIA:
699 case TokenKind.DIRECTIVE_PAGE:
700 case TokenKind.DIRECTIVE_CHARSET:
701 case TokenKind.DIRECTIVE_STYLET:
702 case TokenKind.DIRECTIVE_KEYFRAMES:
703 case TokenKind.DIRECTIVE_WEB_KIT_KEYFRAMES:
704 case TokenKind.DIRECTIVE_MOZ_KEYFRAMES:
705 case TokenKind.DIRECTIVE_MS_KEYFRAMES:
706 case TokenKind.DIRECTIVE_O_KEYFRAMES:
707 case TokenKind.DIRECTIVE_FONTFACE:
708 case TokenKind.DIRECTIVE_NAMESPACE:
709 case TokenKind.DIRECTIVE_HOST:
710 case TokenKind.DIRECTIVE_MIXIN:
711 case TokenKind.DIRECTIVE_INCLUDE:
712 case TokenKind.DIRECTIVE_CONTENT:
713 case TokenKind.UNIT_EM:
714 case TokenKind.UNIT_EX:
715 case TokenKind.UNIT_LENGTH_PX:
716 case TokenKind.UNIT_LENGTH_CM:
717 case TokenKind.UNIT_LENGTH_MM:
718 case TokenKind.UNIT_LENGTH_IN:
719 case TokenKind.UNIT_LENGTH_PT:
720 case TokenKind.UNIT_LENGTH_PC:
721 case TokenKind.UNIT_ANGLE_DEG:
722 case TokenKind.UNIT_ANGLE_RAD:
723 case TokenKind.UNIT_ANGLE_GRAD:
724 case TokenKind.UNIT_TIME_MS:
725 case TokenKind.UNIT_TIME_S:
726 case TokenKind.UNIT_FREQ_HZ:
727 case TokenKind.UNIT_FREQ_KHZ:
728 case TokenKind.UNIT_FRACTION:
729 return true;
730 default:
731 return false;
732 }
733 }
734
735 static bool isIdentifier(int kind) {
736 return kind == IDENTIFIER;
737 }
738 }
739
740 // Note: these names should match TokenKind names
741 class TokenChar {
742 static const int UNUSED = -1;
743 static const int END_OF_FILE = 0;
744 static const int LPAREN = 0x28; // "(".codeUnitAt(0)
745 static const int RPAREN = 0x29; // ")".codeUnitAt(0)
746 static const int LBRACK = 0x5b; // "[".codeUnitAt(0)
747 static const int RBRACK = 0x5d; // "]".codeUnitAt(0)
748 static const int LBRACE = 0x7b; // "{".codeUnitAt(0)
749 static const int RBRACE = 0x7d; // "}".codeUnitAt(0)
750 static const int DOT = 0x2e; // ".".codeUnitAt(0)
751 static const int SEMICOLON = 0x3b; // ";".codeUnitAt(0)
752 static const int AT = 0x40; // "@".codeUnitAt(0)
753 static const int HASH = 0x23; // "#".codeUnitAt(0)
754 static const int PLUS = 0x2b; // "+".codeUnitAt(0)
755 static const int GREATER = 0x3e; // ">".codeUnitAt(0)
756 static const int TILDE = 0x7e; // "~".codeUnitAt(0)
757 static const int ASTERISK = 0x2a; // "*".codeUnitAt(0)
758 static const int NAMESPACE = 0x7c; // "|".codeUnitAt(0)
759 static const int COLON = 0x3a; // ":".codeUnitAt(0)
760 static const int PRIVATE_NAME = 0x5f; // "_".codeUnitAt(0)
761 static const int COMMA = 0x2c; // ",".codeUnitAt(0)
762 static const int SPACE = 0x20; // " ".codeUnitAt(0)
763 static const int TAB = 0x9; // "\t".codeUnitAt(0)
764 static const int NEWLINE = 0xa; // "\n".codeUnitAt(0)
765 static const int RETURN = 0xd; // "\r".codeUnitAt(0)
766 static const int BACKSPACE = 0x8; // "/b".codeUnitAt(0)
767 static const int FF = 0xc; // "/f".codeUnitAt(0)
768 static const int VT = 0xb; // "/v".codeUnitAt(0)
769 static const int PERCENT = 0x25; // "%".codeUnitAt(0)
770 static const int SINGLE_QUOTE = 0x27; // "'".codeUnitAt(0)
771 static const int DOUBLE_QUOTE = 0x22; // '"'.codeUnitAt(0)
772 static const int SLASH = 0x2f; // "/".codeUnitAt(0)
773 static const int EQUALS = 0x3d; // "=".codeUnitAt(0)
774 static const int OR = 0x7c; // "|".codeUnitAt(0)
775 static const int CARET = 0x5e; // "^".codeUnitAt(0)
776 static const int DOLLAR = 0x24; // "\$".codeUnitAt(0)
777 static const int LESS = 0x3c; // "<".codeUnitAt(0)
778 static const int BANG = 0x21; // "!".codeUnitAt(0)
779 static const int MINUS = 0x2d; // "-".codeUnitAt(0)
780 static const int BACKSLASH = 0x5c; // "\".codeUnitAt(0)
781 static const int AMPERSAND = 0x26; // "&".codeUnitAt(0)
782 }
OLDNEW
« no previous file with comments | « csslib/lib/src/tokenizer_base.dart ('k') | csslib/lib/src/tree.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698