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

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

Issue 814113004: Pull args, intl, logging, shelf, and source_maps out of the SDK. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also csslib. Created 6 years 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 | Annotate | Revision Log
« no previous file with comments | « pkg/csslib/lib/src/tokenizer_base.dart ('k') | pkg/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 {'type': TokenKind.DIRECTIVE_WEB_KIT_KEYFRAMES,
203 'value' : '-webkit-keyframes'},
204 const {'type': TokenKind.DIRECTIVE_MOZ_KEYFRAMES,
205 'value' : '-moz-keyframes'},
206 const {'type': TokenKind.DIRECTIVE_MS_KEYFRAMES, 'value' : '-ms-keyframes'},
207 const {'type': TokenKind.DIRECTIVE_O_KEYFRAMES, 'value' : '-o-keyframes'},
208 const {'type': TokenKind.DIRECTIVE_FONTFACE, 'value' : 'font-face'},
209 const {'type': TokenKind.DIRECTIVE_NAMESPACE, 'value' : 'namespace'},
210 const {'type': TokenKind.DIRECTIVE_HOST, 'value' : 'host'},
211 const {'type': TokenKind.DIRECTIVE_MIXIN, 'value' : 'mixin'},
212 const {'type': TokenKind.DIRECTIVE_INCLUDE, 'value' : 'include'},
213 const {'type': TokenKind.DIRECTIVE_CONTENT, 'value' : 'content'},
214 const {'type': TokenKind.DIRECTIVE_EXTEND, 'value' : 'extend'},
215 ];
216
217 static const List<Map<int, String>> MEDIA_OPERATORS = const [
218 const {'type': TokenKind.MEDIA_OP_ONLY, 'value' : 'only'},
219 const {'type': TokenKind.MEDIA_OP_NOT, 'value' : 'not'},
220 const {'type': TokenKind.MEDIA_OP_AND, 'value' : 'and'},
221 ];
222
223 static const List<Map<int, String>> MARGIN_DIRECTIVES = const [
224 const {'type': TokenKind.MARGIN_DIRECTIVE_TOPLEFTCORNER,
225 'value' : 'top-left-corner'},
226 const {'type': TokenKind.MARGIN_DIRECTIVE_TOPLEFT,
227 'value' : 'top-left'},
228 const {'type': TokenKind.MARGIN_DIRECTIVE_TOPCENTER,
229 'value' : 'top-center'},
230 const {'type': TokenKind.MARGIN_DIRECTIVE_TOPRIGHT,
231 'value' : 'top-right'},
232 const {'type': TokenKind.MARGIN_DIRECTIVE_TOPRIGHTCORNER,
233 'value' : 'top-right-corner'},
234 const {'type': TokenKind.MARGIN_DIRECTIVE_BOTTOMLEFTCORNER,
235 'value' : 'bottom-left-corner'},
236 const {'type': TokenKind.MARGIN_DIRECTIVE_BOTTOMLEFT,
237 'value' : 'bottom-left'},
238 const {'type': TokenKind.MARGIN_DIRECTIVE_BOTTOMCENTER,
239 'value' : 'bottom-center'},
240 const {'type': TokenKind.MARGIN_DIRECTIVE_BOTTOMRIGHT,
241 'value' : 'bottom-right'},
242 const {'type': TokenKind.MARGIN_DIRECTIVE_BOTTOMRIGHTCORNER,
243 'value' : 'bottom-right-corner'},
244 const {'type': TokenKind.MARGIN_DIRECTIVE_LEFTTOP,
245 'value' : 'left-top'},
246 const {'type': TokenKind.MARGIN_DIRECTIVE_LEFTMIDDLE,
247 'value' : 'left-middle'},
248 const {'type': TokenKind.MARGIN_DIRECTIVE_LEFTBOTTOM,
249 'value' : 'right-bottom'},
250 const {'type': TokenKind.MARGIN_DIRECTIVE_RIGHTTOP,
251 'value' : 'right-top'},
252 const {'type': TokenKind.MARGIN_DIRECTIVE_RIGHTMIDDLE,
253 'value' : 'right-middle'},
254 const {'type': TokenKind.MARGIN_DIRECTIVE_RIGHTBOTTOM,
255 'value' : 'right-bottom'},
256 ];
257
258 static const List<Map> _UNITS = const [
259 const {'unit': TokenKind.UNIT_EM, 'value' : 'em'},
260 const {'unit': TokenKind.UNIT_EX, 'value' : 'ex'},
261 const {'unit': TokenKind.UNIT_LENGTH_PX, 'value' : 'px'},
262 const {'unit': TokenKind.UNIT_LENGTH_CM, 'value' : 'cm'},
263 const {'unit': TokenKind.UNIT_LENGTH_MM, 'value' : 'mm'},
264 const {'unit': TokenKind.UNIT_LENGTH_IN, 'value' : 'in'},
265 const {'unit': TokenKind.UNIT_LENGTH_PT, 'value' : 'pt'},
266 const {'unit': TokenKind.UNIT_LENGTH_PC, 'value' : 'pc'},
267 const {'unit': TokenKind.UNIT_ANGLE_DEG, 'value' : 'deg'},
268 const {'unit': TokenKind.UNIT_ANGLE_RAD, 'value' : 'rad'},
269 const {'unit': TokenKind.UNIT_ANGLE_GRAD, 'value' : 'grad'},
270 const {'unit': TokenKind.UNIT_ANGLE_TURN, 'value' : 'turn'},
271 const {'unit': TokenKind.UNIT_TIME_MS, 'value' : 'ms'},
272 const {'unit': TokenKind.UNIT_TIME_S, 'value' : 's'},
273 const {'unit': TokenKind.UNIT_FREQ_HZ, 'value' : 'hz'},
274 const {'unit': TokenKind.UNIT_FREQ_KHZ, 'value' : 'khz'},
275 const {'unit': TokenKind.UNIT_FRACTION, 'value' : 'fr'},
276 const {'unit': TokenKind.UNIT_RESOLUTION_DPI, 'value' : 'dpi'},
277 const {'unit': TokenKind.UNIT_RESOLUTION_DPCM, 'value' : 'dpcm'},
278 const {'unit': TokenKind.UNIT_RESOLUTION_DPPX, 'value' : 'dppx'},
279 const {'unit': TokenKind.UNIT_CH, 'value' : 'ch'},
280 const {'unit': TokenKind.UNIT_REM, 'value' : 'rem'},
281 const {'unit': TokenKind.UNIT_VIEWPORT_VW, 'value' : 'vw'},
282 const {'unit': TokenKind.UNIT_VIEWPORT_VH, 'value' : 'vh'},
283 const {'unit': TokenKind.UNIT_VIEWPORT_VMIN, 'value' : 'vmin'},
284 const {'unit': TokenKind.UNIT_VIEWPORT_VMAX, 'value' : 'vmax'},
285 ];
286
287 // Some more constants:
288 static const int ASCII_UPPER_A = 65; // ASCII value for uppercase A
289 static const int ASCII_UPPER_Z = 90; // ASCII value for uppercase Z
290
291 // Extended color keywords:
292 static const List<Map> _EXTENDED_COLOR_NAMES = const [
293 const {'name' : 'aliceblue', 'value' : 0xF08FF},
294 const {'name' : 'antiquewhite', 'value' : 0xFAEBD7},
295 const {'name' : 'aqua', 'value' : 0x00FFFF},
296 const {'name' : 'aquamarine', 'value' : 0x7FFFD4},
297 const {'name' : 'azure', 'value' : 0xF0FFFF},
298 const {'name' : 'beige', 'value' : 0xF5F5DC},
299 const {'name' : 'bisque', 'value' : 0xFFE4C4},
300 const {'name' : 'black', 'value' : 0x000000},
301 const {'name' : 'blanchedalmond', 'value' : 0xFFEBCD},
302 const {'name' : 'blue', 'value' : 0x0000FF},
303 const {'name' : 'blueviolet', 'value' : 0x8A2BE2},
304 const {'name' : 'brown', 'value' : 0xA52A2A},
305 const {'name' : 'burlywood', 'value' : 0xDEB887},
306 const {'name' : 'cadetblue', 'value' : 0x5F9EA0},
307 const {'name' : 'chartreuse', 'value' : 0x7FFF00},
308 const {'name' : 'chocolate', 'value' : 0xD2691E},
309 const {'name' : 'coral', 'value' : 0xFF7F50},
310 const {'name' : 'cornflowerblue', 'value' : 0x6495ED},
311 const {'name' : 'cornsilk', 'value' : 0xFFF8DC},
312 const {'name' : 'crimson', 'value' : 0xDC143C},
313 const {'name' : 'cyan', 'value' : 0x00FFFF},
314 const {'name' : 'darkblue', 'value' : 0x00008B},
315 const {'name' : 'darkcyan', 'value' : 0x008B8B},
316 const {'name' : 'darkgoldenrod', 'value' : 0xB8860B},
317 const {'name' : 'darkgray', 'value' : 0xA9A9A9},
318 const {'name' : 'darkgreen', 'value' : 0x006400},
319 const {'name' : 'darkgrey', 'value' : 0xA9A9A9},
320 const {'name' : 'darkkhaki', 'value' : 0xBDB76B},
321 const {'name' : 'darkmagenta', 'value' : 0x8B008B},
322 const {'name' : 'darkolivegreen', 'value' : 0x556B2F},
323 const {'name' : 'darkorange', 'value' : 0xFF8C00},
324 const {'name' : 'darkorchid', 'value' : 0x9932CC},
325 const {'name' : 'darkred', 'value' : 0x8B0000},
326 const {'name' : 'darksalmon', 'value' : 0xE9967A},
327 const {'name' : 'darkseagreen', 'value' : 0x8FBC8F},
328 const {'name' : 'darkslateblue', 'value' : 0x483D8B},
329 const {'name' : 'darkslategray', 'value' : 0x2F4F4F},
330 const {'name' : 'darkslategrey', 'value' : 0x2F4F4F},
331 const {'name' : 'darkturquoise', 'value' : 0x00CED1},
332 const {'name' : 'darkviolet', 'value' : 0x9400D3},
333 const {'name' : 'deeppink', 'value' : 0xFF1493},
334 const {'name' : 'deepskyblue', 'value' : 0x00BFFF},
335 const {'name' : 'dimgray', 'value' : 0x696969},
336 const {'name' : 'dimgrey', 'value' : 0x696969},
337 const {'name' : 'dodgerblue', 'value' : 0x1E90FF},
338 const {'name' : 'firebrick', 'value' : 0xB22222},
339 const {'name' : 'floralwhite', 'value' : 0xFFFAF0},
340 const {'name' : 'forestgreen', 'value' : 0x228B22},
341 const {'name' : 'fuchsia', 'value' : 0xFF00FF},
342 const {'name' : 'gainsboro', 'value' : 0xDCDCDC},
343 const {'name' : 'ghostwhite', 'value' : 0xF8F8FF},
344 const {'name' : 'gold', 'value' : 0xFFD700},
345 const {'name' : 'goldenrod', 'value' : 0xDAA520},
346 const {'name' : 'gray', 'value' : 0x808080},
347 const {'name' : 'green', 'value' : 0x008000},
348 const {'name' : 'greenyellow', 'value' : 0xADFF2F},
349 const {'name' : 'grey', 'value' : 0x808080},
350 const {'name' : 'honeydew', 'value' : 0xF0FFF0},
351 const {'name' : 'hotpink', 'value' : 0xFF69B4},
352 const {'name' : 'indianred', 'value' : 0xCD5C5C},
353 const {'name' : 'indigo', 'value' : 0x4B0082},
354 const {'name' : 'ivory', 'value' : 0xFFFFF0},
355 const {'name' : 'khaki', 'value' : 0xF0E68C},
356 const {'name' : 'lavender', 'value' : 0xE6E6FA},
357 const {'name' : 'lavenderblush', 'value' : 0xFFF0F5},
358 const {'name' : 'lawngreen', 'value' : 0x7CFC00},
359 const {'name' : 'lemonchiffon', 'value' : 0xFFFACD},
360 const {'name' : 'lightblue', 'value' : 0xADD8E6},
361 const {'name' : 'lightcoral', 'value' : 0xF08080},
362 const {'name' : 'lightcyan', 'value' : 0xE0FFFF},
363 const {'name' : 'lightgoldenrodyellow', 'value' : 0xFAFAD2},
364 const {'name' : 'lightgray', 'value' : 0xD3D3D3},
365 const {'name' : 'lightgreen', 'value' : 0x90EE90},
366 const {'name' : 'lightgrey', 'value' : 0xD3D3D3},
367 const {'name' : 'lightpink', 'value' : 0xFFB6C1},
368 const {'name' : 'lightsalmon', 'value' : 0xFFA07A},
369 const {'name' : 'lightseagreen', 'value' : 0x20B2AA},
370 const {'name' : 'lightskyblue', 'value' : 0x87CEFA},
371 const {'name' : 'lightslategray', 'value' : 0x778899},
372 const {'name' : 'lightslategrey', 'value' : 0x778899},
373 const {'name' : 'lightsteelblue', 'value' : 0xB0C4DE},
374 const {'name' : 'lightyellow', 'value' : 0xFFFFE0},
375 const {'name' : 'lime', 'value' : 0x00FF00},
376 const {'name' : 'limegreen', 'value' : 0x32CD32},
377 const {'name' : 'linen', 'value' : 0xFAF0E6},
378 const {'name' : 'magenta', 'value' : 0xFF00FF},
379 const {'name' : 'maroon', 'value' : 0x800000},
380 const {'name' : 'mediumaquamarine', 'value' : 0x66CDAA},
381 const {'name' : 'mediumblue', 'value' : 0x0000CD},
382 const {'name' : 'mediumorchid', 'value' : 0xBA55D3},
383 const {'name' : 'mediumpurple', 'value' : 0x9370DB},
384 const {'name' : 'mediumseagreen', 'value' : 0x3CB371},
385 const {'name' : 'mediumslateblue', 'value' : 0x7B68EE},
386 const {'name' : 'mediumspringgreen', 'value' : 0x00FA9A},
387 const {'name' : 'mediumturquoise', 'value' : 0x48D1CC},
388 const {'name' : 'mediumvioletred', 'value' : 0xC71585},
389 const {'name' : 'midnightblue', 'value' : 0x191970},
390 const {'name' : 'mintcream', 'value' : 0xF5FFFA},
391 const {'name' : 'mistyrose', 'value' : 0xFFE4E1},
392 const {'name' : 'moccasin', 'value' : 0xFFE4B5},
393 const {'name' : 'navajowhite', 'value' : 0xFFDEAD},
394 const {'name' : 'navy', 'value' : 0x000080},
395 const {'name' : 'oldlace', 'value' : 0xFDF5E6},
396 const {'name' : 'olive', 'value' : 0x808000},
397 const {'name' : 'olivedrab', 'value' : 0x6B8E23},
398 const {'name' : 'orange', 'value' : 0xFFA500},
399 const {'name' : 'orangered', 'value' : 0xFF4500},
400 const {'name' : 'orchid', 'value' : 0xDA70D6},
401 const {'name' : 'palegoldenrod', 'value' : 0xEEE8AA},
402 const {'name' : 'palegreen', 'value' : 0x98FB98},
403 const {'name' : 'paleturquoise', 'value' : 0xAFEEEE},
404 const {'name' : 'palevioletred', 'value' : 0xDB7093},
405 const {'name' : 'papayawhip', 'value' : 0xFFEFD5},
406 const {'name' : 'peachpuff', 'value' : 0xFFDAB9},
407 const {'name' : 'peru', 'value' : 0xCD853F},
408 const {'name' : 'pink', 'value' : 0xFFC0CB},
409 const {'name' : 'plum', 'value' : 0xDDA0DD},
410 const {'name' : 'powderblue', 'value' : 0xB0E0E6},
411 const {'name' : 'purple', 'value' : 0x800080},
412 const {'name' : 'red', 'value' : 0xFF0000},
413 const {'name' : 'rosybrown', 'value' : 0xBC8F8F},
414 const {'name' : 'royalblue', 'value' : 0x4169E1},
415 const {'name' : 'saddlebrown', 'value' : 0x8B4513},
416 const {'name' : 'salmon', 'value' : 0xFA8072},
417 const {'name' : 'sandybrown', 'value' : 0xF4A460},
418 const {'name' : 'seagreen', 'value' : 0x2E8B57},
419 const {'name' : 'seashell', 'value' : 0xFFF5EE},
420 const {'name' : 'sienna', 'value' : 0xA0522D},
421 const {'name' : 'silver', 'value' : 0xC0C0C0},
422 const {'name' : 'skyblue', 'value' : 0x87CEEB},
423 const {'name' : 'slateblue', 'value' : 0x6A5ACD},
424 const {'name' : 'slategray', 'value' : 0x708090},
425 const {'name' : 'slategrey', 'value' : 0x708090},
426 const {'name' : 'snow', 'value' : 0xFFFAFA},
427 const {'name' : 'springgreen', 'value' : 0x00FF7F},
428 const {'name' : 'steelblue', 'value' : 0x4682B4},
429 const {'name' : 'tan', 'value' : 0xD2B48C},
430 const {'name' : 'teal', 'value' : 0x008080},
431 const {'name' : 'thistle', 'value' : 0xD8BFD8},
432 const {'name' : 'tomato', 'value' : 0xFF6347},
433 const {'name' : 'turquoise', 'value' : 0x40E0D0},
434 const {'name' : 'violet', 'value' : 0xEE82EE},
435 const {'name' : 'wheat', 'value' : 0xF5DEB3},
436 const {'name' : 'white', 'value' : 0xFFFFFF},
437 const {'name' : 'whitesmoke', 'value' : 0xF5F5F5},
438 const {'name' : 'yellow', 'value' : 0xFFFF00},
439 const {'name' : 'yellowgreen', 'value' : 0x9ACD32},
440 ];
441
442 // TODO(terry): Should used Dart mirroring for parameter values and types
443 // especially for enumeration (e.g., counter's second parameter
444 // is list-style-type which is an enumerated list for ordering
445 // of a list 'circle', 'decimal', 'lower-roman', 'square', etc.
446 // see http://www.w3schools.com/cssref/pr_list-style-type.asp
447 // for list of possible values.
448
449 // List of valid CSS functions:
450 static const List<Map<String, Object>> _FUNCTIONS = const [
451 const {'name' : 'counter', 'info' : const {'params' : 2, 'expr' : false}},
452 const {'name' : 'attr', 'info' : const {'params' : 1, 'expr' : false}},
453 const {'name' : 'calc', 'info' : const {'params' : 1, 'expr' : true}},
454 const {'name' : 'min', 'info' : const {'params' : 2, 'expr' : true}},
455 const {'name' : 'max', 'info' : const {'params' : 2, 'expr' : true}},
456
457 // 2D functions:
458 const {'name' : 'translateX',
459 'info' : const {'params' : 1, 'expr' : false}},
460 const {'name' : 'translateY',
461 'info' : const {'params' : 1, 'expr' : false}},
462 const {'name' : 'translate', 'info' : const {'params' : 2, 'expr' : false}},
463 const {'name' : 'rotate', 'info' : const {'params' : 1, 'expr' : false}},
464 const {'name' : 'scaleX', 'info' : const {'params' : 1, 'expr' : false}},
465 const {'name' : 'scaleY', 'info' : const {'params' : 1, 'expr' : false}},
466 const {'name' : 'scale', 'info' : const {'params' : 2, 'expr' : false}},
467 const {'name' : 'skewX', 'info' : const {'params' : 1, 'expr' : false}},
468 const {'name' : 'skewY', 'info' : const {'params' : 1, 'expr' : false}},
469 const {'name' : 'skew', 'info' : const {'params' : 2, 'expr' : false}},
470 const {'name' : 'matrix', 'info' : const {'params' : 6, 'expr' : false}},
471
472 // 3D functions:
473 const {'name' : 'matrix3d', 'info' : const {'params' : 16, 'expr' : false}},
474 const {'name' : 'translate3d',
475 'info' : const {'params' : 3, 'expr' : false}},
476 const {'name' : 'translateZ',
477 'info' : const {'params' : 1, 'expr' : false}},
478 const {'name' : 'scale3d', 'info' : const {'params' : 3, 'expr' : false}},
479 const {'name' : 'scaleZ', 'info' : const {'params' : 1, 'expr' : false}},
480 const {'name' : 'rotate3d', 'info' : const {'params' : 3, 'expr' : false}},
481 const {'name' : 'rotateX', 'info' : const {'params' : 1, 'expr' : false}},
482 const {'name' : 'rotateY', 'info' : const {'params' : 1, 'expr' : false}},
483 const {'name' : 'rotateZ', 'info' : const {'params' : 1, 'expr' : false}},
484 const {'name' : 'perspective',
485 'info' : const {'params' : 1, 'expr' : false}},
486 ];
487
488 /**
489 * Check if name is a pre-defined CSS name. Used by error handler to report
490 * if name is unknown or used improperly.
491 */
492 static bool isPredefinedName(String name) {
493 var nameLen = name.length;
494 // TODO(terry): Add more pre-defined names (hidden, bolder, inherit, etc.).
495 if (matchUnits(name, 0, nameLen) == -1 ||
496 matchDirectives(name, 0, nameLen) == -1 ||
497 matchMarginDirectives(name, 0, nameLen) == -1 ||
498 matchColorName(name) == null) {
499 return false;
500 }
501
502 return true;
503 }
504
505 /** Return the token that matches the unit ident found. */
506 static int matchList(var identList, String tokenField, String text,
507 int offset, int length) {
508 for (final entry in identList) {
509 String ident = entry['value'];
510
511 if (length == ident.length) {
512 int idx = offset;
513 bool match = true;
514 for (int i = 0; i < ident.length; i++) {
515 int identChar = ident.codeUnitAt(i);
516 int char = text.codeUnitAt(idx++);
517 // Compare lowercase to lowercase then check if char is uppercase.
518 match = match && (char == identChar ||
519 ((char >= ASCII_UPPER_A && char <= ASCII_UPPER_Z) &&
520 (char + 32) == identChar));
521 if (!match) {
522 break;
523 }
524 }
525
526 if (match) {
527 // Completely matched; return the token for this unit.
528 return entry[tokenField];
529 }
530 }
531 }
532
533 return -1; // Not a unit token.
534 }
535
536 /** Return the token that matches the unit ident found. */
537 static int matchUnits(String text, int offset, int length) {
538 return matchList(_UNITS, 'unit', text, offset, length);
539 }
540
541 /** Return the token that matches the directive name found. */
542 static int matchDirectives(String text, int offset, int length) {
543 return matchList(_DIRECTIVES, 'type', text, offset, length);
544 }
545
546 /** Return the token that matches the margin directive name found. */
547 static int matchMarginDirectives(String text, int offset, int length) {
548 return matchList(MARGIN_DIRECTIVES, 'type', text, offset, length);
549 }
550
551 /** Return the token that matches the media operator found. */
552 static int matchMediaOperator(String text, int offset, int length) {
553 return matchList(MEDIA_OPERATORS, 'type', text, offset, length);
554 }
555
556 static String idToValue(var identList, int tokenId) {
557 for (var entry in identList) {
558 if (tokenId == entry['type']) {
559 return entry['value'];
560 }
561 }
562
563 return null;
564 }
565
566
567 /** Return the unit token as its pretty name. */
568 static String unitToString(int unitTokenToFind) {
569 if (unitTokenToFind == TokenKind.PERCENT) {
570 return '%';
571 } else {
572 for (final entry in _UNITS) {
573 int unit = entry['unit'];
574 if (unit == unitTokenToFind) {
575 return entry['value'];
576 }
577 }
578 }
579
580 return '<BAD UNIT>'; // Not a unit token.
581 }
582
583 /**
584 * Match color name, case insensitive match and return the associated color
585 * entry from _EXTENDED_COLOR_NAMES list, return [:null:] if not found.
586 */
587 static Map matchColorName(String text) {
588 var name = text.toLowerCase();
589 return _EXTENDED_COLOR_NAMES.
590 firstWhere((e) => e['name'] == name, orElse: () => null);
591 }
592
593 /** Return RGB value as [int] from a color entry in _EXTENDED_COLOR_NAMES. */
594 static int colorValue(Map entry) {
595 assert(entry != null);
596 return entry['value'];
597 }
598
599 static String hexToColorName(hexValue) {
600 for (final entry in _EXTENDED_COLOR_NAMES) {
601 if (entry['value'] == hexValue) {
602 return entry['name'];
603 }
604 }
605
606 return null;
607 }
608
609 static String decimalToHex(int number, [int minDigits = 1]) {
610 final String _HEX_DIGITS = '0123456789abcdef';
611
612 List<String> result = new List<String>();
613
614 int dividend = number >> 4;
615 int remain = number % 16;
616 result.add(_HEX_DIGITS[remain]);
617 while (dividend != 0) {
618 remain = dividend % 16;
619 dividend >>= 4;
620 result.add(_HEX_DIGITS[remain]);
621 }
622
623 StringBuffer invertResult = new StringBuffer();
624 int paddings = minDigits - result.length;
625 while (paddings-- > 0) {
626 invertResult.write('0');
627 }
628 for (int i = result.length - 1; i >= 0; i--) {
629 invertResult.write(result[i]);
630 }
631
632 return invertResult.toString();
633 }
634
635 static String kindToString(int kind) {
636 switch(kind) {
637 case TokenKind.UNUSED: return "ERROR";
638 case TokenKind.END_OF_FILE: return "end of file";
639 case TokenKind.LPAREN: return "(";
640 case TokenKind.RPAREN: return ")";
641 case TokenKind.LBRACK: return "[";
642 case TokenKind.RBRACK: return "]";
643 case TokenKind.LBRACE: return "{";
644 case TokenKind.RBRACE: return "}";
645 case TokenKind.DOT: return ".";
646 case TokenKind.SEMICOLON: return ";";
647 case TokenKind.AT: return "@";
648 case TokenKind.HASH: return "#";
649 case TokenKind.PLUS: return "+";
650 case TokenKind.GREATER: return ">";
651 case TokenKind.TILDE: return "~";
652 case TokenKind.ASTERISK: return "*";
653 case TokenKind.NAMESPACE: return "|";
654 case TokenKind.COLON: return ":";
655 case TokenKind.PRIVATE_NAME: return "_";
656 case TokenKind.COMMA: return ",";
657 case TokenKind.SPACE: return " ";
658 case TokenKind.TAB: return "\t";
659 case TokenKind.NEWLINE: return "\n";
660 case TokenKind.RETURN: return "\r";
661 case TokenKind.PERCENT: return "%";
662 case TokenKind.SINGLE_QUOTE: return "'";
663 case TokenKind.DOUBLE_QUOTE: return "\"";
664 case TokenKind.SLASH: return "/";
665 case TokenKind.EQUALS: return '=';
666 case TokenKind.CARET: return '^';
667 case TokenKind.DOLLAR: return '\$';
668 case TokenKind.LESS: return '<';
669 case TokenKind.BANG: return '!';
670 case TokenKind.MINUS: return '-';
671 case TokenKind.BACKSLASH: return '\\';
672 default:
673 throw "Unknown TOKEN";
674 }
675 }
676
677 static bool isKindIdentifier(int kind) {
678 switch(kind) {
679 // Synthesized tokens.
680 case TokenKind.DIRECTIVE_IMPORT:
681 case TokenKind.DIRECTIVE_MEDIA:
682 case TokenKind.DIRECTIVE_PAGE:
683 case TokenKind.DIRECTIVE_CHARSET:
684 case TokenKind.DIRECTIVE_STYLET:
685 case TokenKind.DIRECTIVE_KEYFRAMES:
686 case TokenKind.DIRECTIVE_WEB_KIT_KEYFRAMES:
687 case TokenKind.DIRECTIVE_MOZ_KEYFRAMES:
688 case TokenKind.DIRECTIVE_MS_KEYFRAMES:
689 case TokenKind.DIRECTIVE_O_KEYFRAMES:
690 case TokenKind.DIRECTIVE_FONTFACE:
691 case TokenKind.DIRECTIVE_NAMESPACE:
692 case TokenKind.DIRECTIVE_HOST:
693 case TokenKind.DIRECTIVE_MIXIN:
694 case TokenKind.DIRECTIVE_INCLUDE:
695 case TokenKind.DIRECTIVE_CONTENT:
696 case TokenKind.UNIT_EM:
697 case TokenKind.UNIT_EX:
698 case TokenKind.UNIT_LENGTH_PX:
699 case TokenKind.UNIT_LENGTH_CM:
700 case TokenKind.UNIT_LENGTH_MM:
701 case TokenKind.UNIT_LENGTH_IN:
702 case TokenKind.UNIT_LENGTH_PT:
703 case TokenKind.UNIT_LENGTH_PC:
704 case TokenKind.UNIT_ANGLE_DEG:
705 case TokenKind.UNIT_ANGLE_RAD:
706 case TokenKind.UNIT_ANGLE_GRAD:
707 case TokenKind.UNIT_TIME_MS:
708 case TokenKind.UNIT_TIME_S:
709 case TokenKind.UNIT_FREQ_HZ:
710 case TokenKind.UNIT_FREQ_KHZ:
711 case TokenKind.UNIT_FRACTION:
712 return true;
713 default:
714 return false;
715 }
716 }
717
718 static bool isIdentifier(int kind) {
719 return kind == IDENTIFIER ;
720 }
721 }
722
723 // Note: these names should match TokenKind names
724 class TokenChar {
725 static const int UNUSED = -1;
726 static const int END_OF_FILE = 0;
727 static const int LPAREN = 0x28; // "(".codeUnitAt(0)
728 static const int RPAREN = 0x29; // ")".codeUnitAt(0)
729 static const int LBRACK = 0x5b; // "[".codeUnitAt(0)
730 static const int RBRACK = 0x5d; // "]".codeUnitAt(0)
731 static const int LBRACE = 0x7b; // "{".codeUnitAt(0)
732 static const int RBRACE = 0x7d; // "}".codeUnitAt(0)
733 static const int DOT = 0x2e; // ".".codeUnitAt(0)
734 static const int SEMICOLON = 0x3b; // ";".codeUnitAt(0)
735 static const int AT = 0x40; // "@".codeUnitAt(0)
736 static const int HASH = 0x23; // "#".codeUnitAt(0)
737 static const int PLUS = 0x2b; // "+".codeUnitAt(0)
738 static const int GREATER = 0x3e; // ">".codeUnitAt(0)
739 static const int TILDE = 0x7e; // "~".codeUnitAt(0)
740 static const int ASTERISK = 0x2a; // "*".codeUnitAt(0)
741 static const int NAMESPACE = 0x7c; // "|".codeUnitAt(0)
742 static const int COLON = 0x3a; // ":".codeUnitAt(0)
743 static const int PRIVATE_NAME = 0x5f; // "_".codeUnitAt(0)
744 static const int COMMA = 0x2c; // ",".codeUnitAt(0)
745 static const int SPACE = 0x20; // " ".codeUnitAt(0)
746 static const int TAB = 0x9; // "\t".codeUnitAt(0)
747 static const int NEWLINE = 0xa; // "\n".codeUnitAt(0)
748 static const int RETURN = 0xd; // "\r".codeUnitAt(0)
749 static const int BACKSPACE = 0x8; // "/b".codeUnitAt(0)
750 static const int FF = 0xc; // "/f".codeUnitAt(0)
751 static const int VT = 0xb; // "/v".codeUnitAt(0)
752 static const int PERCENT = 0x25; // "%".codeUnitAt(0)
753 static const int SINGLE_QUOTE = 0x27; // "'".codeUnitAt(0)
754 static const int DOUBLE_QUOTE = 0x22; // '"'.codeUnitAt(0)
755 static const int SLASH = 0x2f; // "/".codeUnitAt(0)
756 static const int EQUALS = 0x3d; // "=".codeUnitAt(0)
757 static const int OR = 0x7c; // "|".codeUnitAt(0)
758 static const int CARET = 0x5e; // "^".codeUnitAt(0)
759 static const int DOLLAR = 0x24; // "\$".codeUnitAt(0)
760 static const int LESS = 0x3c; // "<".codeUnitAt(0)
761 static const int BANG = 0x21; // "!".codeUnitAt(0)
762 static const int MINUS = 0x2d; // "-".codeUnitAt(0)
763 static const int BACKSLASH = 0x5c; // "\".codeUnitAt(0)
764 static const int AMPERSAND = 0x26; // "&".codeUnitAt(0)
765 }
OLDNEW
« no previous file with comments | « pkg/csslib/lib/src/tokenizer_base.dart ('k') | pkg/csslib/lib/src/tree.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698