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

Side by Side Diff: utils/css/tokenkind.dart

Issue 137013002: Removed obsolete code (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed libraries not used Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « utils/css/tokenizer_base.dart ('k') | utils/css/tool.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) 2011, 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 // TODO(terry): Need to be consistent with tokens either they're ASCII tokens
6 // e.g., ASTERISK or they're CSS e.g., PSEUDO, COMBINATOR_*.
7 class TokenKind {
8 // Common shared tokens used in TokenizerBase.
9 static const int UNUSED = 0; // Unused place holder...
10 static const int END_OF_FILE = 1; // TODO(terry): Must match base
11 static const int LPAREN = 2; // (
12 static const int RPAREN = 3; // )
13 static const int LBRACK = 4; // [
14 static const int RBRACK = 5; // ]
15 static const int LBRACE = 6; // {
16 static const int RBRACE = 7; // }
17 static const int DOT = 8; // .
18 static const int SEMICOLON = 9; // ;
19
20 // Unique tokens for CSS.
21 static const int AT = 10; // @
22 static const int HASH = 11; // #
23 static const int PLUS = 12; // +
24 static const int GREATER = 13; // >
25 static const int TILDE = 14; // ~
26 static const int ASTERISK = 15; // *
27 static const int NAMESPACE = 16; // |
28 static const int COLON = 17; // :
29 static const int PRIVATE_NAME = 18; // _ prefix private class or id
30 static const int COMMA = 19; // ,
31 static const int SPACE = 20;
32 static const int TAB = 21; // /t
33 static const int NEWLINE = 22; // /n
34 static const int RETURN = 23; // /r
35 static const int PERCENT = 24; // %
36 static const int SINGLE_QUOTE = 25; // '
37 static const int DOUBLE_QUOTE = 26; // "
38 static const int SLASH = 27; // /
39 static const int EQUALS = 28; // =
40 static const int OR = 29; // |
41 static const int CARET = 30; // ^
42 static const int DOLLAR = 31; // $
43 static const int LESS = 32; // <
44 static const int BANG = 33; // !
45 static const int MINUS = 34; // -
46
47 // WARNING: END_TOKENS must be 1 greater than the last token above (last
48 // character in our list). Also add to kindToString function and the
49 // constructor for TokenKind.
50
51 static const int END_TOKENS = 35; // Marker for last token in list
52
53 /** [TokenKind] representing integer tokens. */
54 static const int INTEGER = 60; // TODO(terry): must match base
55
56 /** [TokenKind] representing hex integer tokens. */
57 // static const int HEX_INTEGER = 61; // TODO(terry): must match bas e
58
59 /** [TokenKind] representing double tokens. */
60 static const int DOUBLE = 62; // TODO(terry): must match base
61
62 /** [TokenKind] representing whitespace tokens. */
63 static const int WHITESPACE = 63; // TODO(terry): must match base
64
65 /** [TokenKind] representing comment tokens. */
66 static const int COMMENT = 64; // TODO(terry): must match base
67
68 /** [TokenKind] representing error tokens. */
69 static const int ERROR = 65; // TODO(terry): must match base
70
71 /** [TokenKind] representing incomplete string tokens. */
72 static const int INCOMPLETE_STRING = 66; // TODO(terry): must match base
73
74 /** [TokenKind] representing incomplete comment tokens. */
75 static const int INCOMPLETE_COMMENT = 67; // TODO(terry): must match base
76
77 // Synthesized Tokens (no character associated with TOKEN).
78 // TODO(terry): Possible common names used by both Dart and CSS tokenizers.
79 static const int STRING = 500;
80 static const int STRING_PART = 501;
81 static const int NUMBER = 502;
82 static const int HEX_NUMBER = 503;
83 static const int HTML_COMMENT = 504; // <!--
84 static const int IMPORTANT = 505; // !important
85 static const int IDENTIFIER = 511;
86
87 // Uniquely synthesized tokens for CSS.
88 static const int SELECTOR_EXPRESSION = 512;
89 static const int COMBINATOR_NONE = 513;
90 static const int COMBINATOR_DESCENDANT = 514; // Space combinator
91 static const int COMBINATOR_PLUS = 515; // + combinator
92 static const int COMBINATOR_GREATER = 516; // > combinator
93 static const int COMBINATOR_TILDE = 517; // ~ combinator
94
95 static const int UNARY_OP_NONE = 518; // No unary operator present.
96
97 // Attribute match types:
98 static const int INCLUDES = 530; // '~='
99 static const int DASH_MATCH = 531; // '|='
100 static const int PREFIX_MATCH = 532; // '^='
101 static const int SUFFIX_MATCH = 533; // '$='
102 static const int SUBSTRING_MATCH = 534; // '*='
103 static const int NO_MATCH = 535; // No operator.
104
105 // Unit types:
106 static const int UNIT_EM = 600;
107 static const int UNIT_EX = 601;
108 static const int UNIT_LENGTH_PX = 602;
109 static const int UNIT_LENGTH_CM = 603;
110 static const int UNIT_LENGTH_MM = 604;
111 static const int UNIT_LENGTH_IN = 605;
112 static const int UNIT_LENGTH_PT = 606;
113 static const int UNIT_LENGTH_PC = 607;
114 static const int UNIT_ANGLE_DEG = 608;
115 static const int UNIT_ANGLE_RAD = 609;
116 static const int UNIT_ANGLE_GRAD = 610;
117 static const int UNIT_TIME_MS = 611;
118 static const int UNIT_TIME_S = 612;
119 static const int UNIT_FREQ_HZ = 613;
120 static const int UNIT_FREQ_KHZ = 614;
121 static const int UNIT_PERCENT = 615;
122 static const int UNIT_FRACTION = 616;
123
124 // Directives (@nnnn)
125 static const int DIRECTIVE_NONE = 650;
126 static const int DIRECTIVE_IMPORT = 651;
127 static const int DIRECTIVE_MEDIA = 652;
128 static const int DIRECTIVE_PAGE = 653;
129 static const int DIRECTIVE_INCLUDE = 654;
130 static const int DIRECTIVE_STYLET = 655;
131 static const int DIRECTIVE_KEYFRAMES = 656;
132 static const int DIRECTIVE_FONTFACE = 657;
133
134 // Simple selector type.
135 static const int CLASS_NAME = 700; // .class
136 static const int ELEMENT_NAME = 701; // tagName
137 static const int HASH_NAME = 702; // #elementId
138 static const int ATTRIBUTE_NAME = 703; // [attrib]
139 static const int PSEUDO_ELEMENT_NAME = 704; // ::pseudoElement
140 static const int PSEUDO_CLASS_NAME = 705; // :pseudoClass
141 static const int NEGATION = 706; // NOT
142
143 static const List<Map<int, String>> _DIRECTIVES = const [
144 const {'type': TokenKind.DIRECTIVE_IMPORT, 'value' : 'import'},
145 const {'type': TokenKind.DIRECTIVE_MEDIA, 'value' : 'media'},
146 const {'type': TokenKind.DIRECTIVE_PAGE, 'value' : 'page'},
147 const {'type': TokenKind.DIRECTIVE_INCLUDE, 'value' : 'include'},
148 const {'type': TokenKind.DIRECTIVE_STYLET, 'value' : 'stylet'},
149 const {'type': TokenKind.DIRECTIVE_KEYFRAMES, 'value' : '-webkit-keyframes'} ,
150 const {'type': TokenKind.DIRECTIVE_FONTFACE, 'value' : 'font-face'},
151 ];
152
153 static const List<Map<int, String>> _UNITS = const [
154 const {'unit': TokenKind.UNIT_EM, 'value' : 'em'},
155 const {'unit': TokenKind.UNIT_EX, 'value' : 'ex'},
156 const {'unit': TokenKind.UNIT_LENGTH_PX, 'value' : 'px'},
157 const {'unit': TokenKind.UNIT_LENGTH_CM, 'value' : 'cm'},
158 const {'unit': TokenKind.UNIT_LENGTH_MM, 'value' : 'mm'},
159 const {'unit': TokenKind.UNIT_LENGTH_IN, 'value' : 'in'},
160 const {'unit': TokenKind.UNIT_LENGTH_PT, 'value' : 'pt'},
161 const {'unit': TokenKind.UNIT_LENGTH_PC, 'value' : 'pc'},
162 const {'unit': TokenKind.UNIT_ANGLE_DEG, 'value' : 'deg'},
163 const {'unit': TokenKind.UNIT_ANGLE_RAD, 'value' : 'rad'},
164 const {'unit': TokenKind.UNIT_ANGLE_GRAD, 'value' : 'grad'},
165 const {'unit': TokenKind.UNIT_TIME_MS, 'value' : 'ms'},
166 const {'unit': TokenKind.UNIT_TIME_S, 'value' : 's'},
167 const {'unit': TokenKind.UNIT_FREQ_HZ, 'value' : 'hz'},
168 const {'unit': TokenKind.UNIT_FREQ_KHZ, 'value' : 'khz'},
169 const {'unit': TokenKind.UNIT_FRACTION, 'value' : 'fr'},
170 ];
171
172 // Some more constants:
173 static const int ASCII_UPPER_A = 65; // ASCII value for uppercase A
174 static const int ASCII_UPPER_Z = 90; // ASCII value for uppercase Z
175
176 // Extended color keywords:
177 static const List<Map<String, int>> _EXTENDED_COLOR_NAMES = const [
178 const {'name' : 'aliceblue', 'value' : 0xF08FF},
179 const {'name' : 'antiquewhite', 'value' : 0xFAEBD7},
180 const {'name' : 'aqua', 'value' : 0x00FFFF},
181 const {'name' : 'aquamarine', 'value' : 0x7FFFD4},
182 const {'name' : 'azure', 'value' : 0xF0FFFF},
183 const {'name' : 'beige', 'value' : 0xF5F5DC},
184 const {'name' : 'bisque', 'value' : 0xFFE4C4},
185 const {'name' : 'black', 'value' : 0x000000},
186 const {'name' : 'blanchedalmond', 'value' : 0xFFEBCD},
187 const {'name' : 'blue', 'value' : 0x0000FF},
188 const {'name' : 'blueviolet', 'value' : 0x8A2BE2},
189 const {'name' : 'brown', 'value' : 0xA52A2A},
190 const {'name' : 'burlywood', 'value' : 0xDEB887},
191 const {'name' : 'cadetblue', 'value' : 0x5F9EA0},
192 const {'name' : 'chartreuse', 'value' : 0x7FFF00},
193 const {'name' : 'chocolate', 'value' : 0xD2691E},
194 const {'name' : 'coral', 'value' : 0xFF7F50},
195 const {'name' : 'cornflowerblue', 'value' : 0x6495ED},
196 const {'name' : 'cornsilk', 'value' : 0xFFF8DC},
197 const {'name' : 'crimson', 'value' : 0xDC143C},
198 const {'name' : 'cyan', 'value' : 0x00FFFF},
199 const {'name' : 'darkblue', 'value' : 0x00008B},
200 const {'name' : 'darkcyan', 'value' : 0x008B8B},
201 const {'name' : 'darkgoldenrod', 'value' : 0xB8860B},
202 const {'name' : 'darkgray', 'value' : 0xA9A9A9},
203 const {'name' : 'darkgreen', 'value' : 0x006400},
204 const {'name' : 'darkgrey', 'value' : 0xA9A9A9},
205 const {'name' : 'darkkhaki', 'value' : 0xBDB76B},
206 const {'name' : 'darkmagenta', 'value' : 0x8B008B},
207 const {'name' : 'darkolivegreen', 'value' : 0x556B2F},
208 const {'name' : 'darkorange', 'value' : 0xFF8C00},
209 const {'name' : 'darkorchid', 'value' : 0x9932CC},
210 const {'name' : 'darkred', 'value' : 0x8B0000},
211 const {'name' : 'darksalmon', 'value' : 0xE9967A},
212 const {'name' : 'darkseagreen', 'value' : 0x8FBC8F},
213 const {'name' : 'darkslateblue', 'value' : 0x483D8B},
214 const {'name' : 'darkslategray', 'value' : 0x2F4F4F},
215 const {'name' : 'darkslategrey', 'value' : 0x2F4F4F},
216 const {'name' : 'darkturquoise', 'value' : 0x00CED1},
217 const {'name' : 'darkviolet', 'value' : 0x9400D3},
218 const {'name' : 'deeppink', 'value' : 0xFF1493},
219 const {'name' : 'deepskyblue', 'value' : 0x00BFFF},
220 const {'name' : 'dimgray', 'value' : 0x696969},
221 const {'name' : 'dimgrey', 'value' : 0x696969},
222 const {'name' : 'dodgerblue', 'value' : 0x1E90FF},
223 const {'name' : 'firebrick', 'value' : 0xB22222},
224 const {'name' : 'floralwhite', 'value' : 0xFFFAF0},
225 const {'name' : 'forestgreen', 'value' : 0x228B22},
226 const {'name' : 'fuchsia', 'value' : 0xFF00FF},
227 const {'name' : 'gainsboro', 'value' : 0xDCDCDC},
228 const {'name' : 'ghostwhite', 'value' : 0xF8F8FF},
229 const {'name' : 'gold', 'value' : 0xFFD700},
230 const {'name' : 'goldenrod', 'value' : 0xDAA520},
231 const {'name' : 'gray', 'value' : 0x808080},
232 const {'name' : 'green', 'value' : 0x008000},
233 const {'name' : 'greenyellow', 'value' : 0xADFF2F},
234 const {'name' : 'grey', 'value' : 0x808080},
235 const {'name' : 'honeydew', 'value' : 0xF0FFF0},
236 const {'name' : 'hotpink', 'value' : 0xFF69B4},
237 const {'name' : 'indianred', 'value' : 0xCD5C5C},
238 const {'name' : 'indigo', 'value' : 0x4B0082},
239 const {'name' : 'ivory', 'value' : 0xFFFFF0},
240 const {'name' : 'khaki', 'value' : 0xF0E68C},
241 const {'name' : 'lavender', 'value' : 0xE6E6FA},
242 const {'name' : 'lavenderblush', 'value' : 0xFFF0F5},
243 const {'name' : 'lawngreen', 'value' : 0x7CFC00},
244 const {'name' : 'lemonchiffon', 'value' : 0xFFFACD},
245 const {'name' : 'lightblue', 'value' : 0xADD8E6},
246 const {'name' : 'lightcoral', 'value' : 0xF08080},
247 const {'name' : 'lightcyan', 'value' : 0xE0FFFF},
248 const {'name' : 'lightgoldenrodyellow', 'value' : 0xFAFAD2},
249 const {'name' : 'lightgray', 'value' : 0xD3D3D3},
250 const {'name' : 'lightgreen', 'value' : 0x90EE90},
251 const {'name' : 'lightgrey', 'value' : 0xD3D3D3},
252 const {'name' : 'lightpink', 'value' : 0xFFB6C1},
253 const {'name' : 'lightsalmon', 'value' : 0xFFA07A},
254 const {'name' : 'lightseagreen', 'value' : 0x20B2AA},
255 const {'name' : 'lightskyblue', 'value' : 0x87CEFA},
256 const {'name' : 'lightslategray', 'value' : 0x778899},
257 const {'name' : 'lightslategrey', 'value' : 0x778899},
258 const {'name' : 'lightsteelblue', 'value' : 0xB0C4DE},
259 const {'name' : 'lightyellow', 'value' : 0xFFFFE0},
260 const {'name' : 'lime', 'value' : 0x00FF00},
261 const {'name' : 'limegreen', 'value' : 0x32CD32},
262 const {'name' : 'linen', 'value' : 0xFAF0E6},
263 const {'name' : 'magenta', 'value' : 0xFF00FF},
264 const {'name' : 'maroon', 'value' : 0x800000},
265 const {'name' : 'mediumaquamarine', 'value' : 0x66CDAA},
266 const {'name' : 'mediumblue', 'value' : 0x0000CD},
267 const {'name' : 'mediumorchid', 'value' : 0xBA55D3},
268 const {'name' : 'mediumpurple', 'value' : 0x9370DB},
269 const {'name' : 'mediumseagreen', 'value' : 0x3CB371},
270 const {'name' : 'mediumslateblue', 'value' : 0x7B68EE},
271 const {'name' : 'mediumspringgreen', 'value' : 0x00FA9A},
272 const {'name' : 'mediumturquoise', 'value' : 0x48D1CC},
273 const {'name' : 'mediumvioletred', 'value' : 0xC71585},
274 const {'name' : 'midnightblue', 'value' : 0x191970},
275 const {'name' : 'mintcream', 'value' : 0xF5FFFA},
276 const {'name' : 'mistyrose', 'value' : 0xFFE4E1},
277 const {'name' : 'moccasin', 'value' : 0xFFE4B5},
278 const {'name' : 'navajowhite', 'value' : 0xFFDEAD},
279 const {'name' : 'navy', 'value' : 0x000080},
280 const {'name' : 'oldlace', 'value' : 0xFDF5E6},
281 const {'name' : 'olive', 'value' : 0x808000},
282 const {'name' : 'olivedrab', 'value' : 0x6B8E23},
283 const {'name' : 'orange', 'value' : 0xFFA500},
284 const {'name' : 'orangered', 'value' : 0xFF4500},
285 const {'name' : 'orchid', 'value' : 0xDA70D6},
286 const {'name' : 'palegoldenrod', 'value' : 0xEEE8AA},
287 const {'name' : 'palegreen', 'value' : 0x98FB98},
288 const {'name' : 'paleturquoise', 'value' : 0xAFEEEE},
289 const {'name' : 'palevioletred', 'value' : 0xDB7093},
290 const {'name' : 'papayawhip', 'value' : 0xFFEFD5},
291 const {'name' : 'peachpuff', 'value' : 0xFFDAB9},
292 const {'name' : 'peru', 'value' : 0xCD853F},
293 const {'name' : 'pink', 'value' : 0xFFC0CB},
294 const {'name' : 'plum', 'value' : 0xDDA0DD},
295 const {'name' : 'powderblue', 'value' : 0xB0E0E6},
296 const {'name' : 'purple', 'value' : 0x800080},
297 const {'name' : 'red', 'value' : 0xFF0000},
298 const {'name' : 'rosybrown', 'value' : 0xBC8F8F},
299 const {'name' : 'royalblue', 'value' : 0x4169E1},
300 const {'name' : 'saddlebrown', 'value' : 0x8B4513},
301 const {'name' : 'salmon', 'value' : 0xFA8072},
302 const {'name' : 'sandybrown', 'value' : 0xF4A460},
303 const {'name' : 'seagreen', 'value' : 0x2E8B57},
304 const {'name' : 'seashell', 'value' : 0xFFF5EE},
305 const {'name' : 'sienna', 'value' : 0xA0522D},
306 const {'name' : 'silver', 'value' : 0xC0C0C0},
307 const {'name' : 'skyblue', 'value' : 0x87CEEB},
308 const {'name' : 'slateblue', 'value' : 0x6A5ACD},
309 const {'name' : 'slategray', 'value' : 0x708090},
310 const {'name' : 'slategrey', 'value' : 0x708090},
311 const {'name' : 'snow', 'value' : 0xFFFAFA},
312 const {'name' : 'springgreen', 'value' : 0x00FF7F},
313 const {'name' : 'steelblue', 'value' : 0x4682B4},
314 const {'name' : 'tan', 'value' : 0xD2B48C},
315 const {'name' : 'teal', 'value' : 0x008080},
316 const {'name' : 'thistle', 'value' : 0xD8BFD8},
317 const {'name' : 'tomato', 'value' : 0xFF6347},
318 const {'name' : 'turquoise', 'value' : 0x40E0D0},
319 const {'name' : 'violet', 'value' : 0xEE82EE},
320 const {'name' : 'wheat', 'value' : 0xF5DEB3},
321 const {'name' : 'white', 'value' : 0xFFFFFF},
322 const {'name' : 'whitesmoke', 'value' : 0xF5F5F5},
323 const {'name' : 'yellow', 'value' : 0xFFFF00},
324 const {'name' : 'yellowgreen', 'value' : 0x9ACD32},
325 ];
326
327 // TODO(terry): Should used Dart mirroring for parameter values and types
328 // especially for enumeration (e.g., counter's second parameter
329 // is list-style-type which is an enumerated list for ordering
330 // of a list 'circle', 'decimal', 'lower-roman', 'square', etc.
331 // see http://www.w3schools.com/cssref/pr_list-style-type.asp
332 // for list of possible values.
333
334 // List of valid CSS functions:
335 static const List<Map<String, Object>> _FUNCTIONS = const [
336 const {'name' : 'counter', 'info' : const {'params' : 2, 'expr' : false}},
337 const {'name' : 'attr', 'info' : const {'params' : 1, 'expr' : false}},
338 const {'name' : 'calc', 'info' : const {'params' : 1, 'expr' : true}},
339 const {'name' : 'min', 'info' : const {'params' : 2, 'expr' : true}},
340 const {'name' : 'max', 'info' : const {'params' : 2, 'expr' : true}},
341
342 // 2D functions:
343 const {'name' : 'translateX',
344 'info' : const {'params' : 1, 'expr' : false}},
345 const {'name' : 'translateY',
346 'info' : const {'params' : 1, 'expr' : false}},
347 const {'name' : 'translate', 'info' : const {'params' : 2, 'expr' : false}},
348 const {'name' : 'rotate', 'info' : const {'params' : 1, 'expr' : false}},
349 const {'name' : 'scaleX', 'info' : const {'params' : 1, 'expr' : false}},
350 const {'name' : 'scaleY', 'info' : const {'params' : 1, 'expr' : false}},
351 const {'name' : 'scale', 'info' : const {'params' : 2, 'expr' : false}},
352 const {'name' : 'skewX', 'info' : const {'params' : 1, 'expr' : false}},
353 const {'name' : 'skewY', 'info' : const {'params' : 1, 'expr' : false}},
354 const {'name' : 'skew', 'info' : const {'params' : 2, 'expr' : false}},
355 const {'name' : 'matrix', 'info' : const {'params' : 6, 'expr' : false}},
356
357 // 3D functions:
358 const {'name' : 'matrix3d', 'info' : const {'params' : 16, 'expr' : false}},
359 const {'name' : 'translate3d',
360 'info' : const {'params' : 3, 'expr' : false}},
361 const {'name' : 'translateZ',
362 'info' : const {'params' : 1, 'expr' : false}},
363 const {'name' : 'scale3d', 'info' : const {'params' : 3, 'expr' : false}},
364 const {'name' : 'scaleZ', 'info' : const {'params' : 1, 'expr' : false}},
365 const {'name' : 'rotate3d', 'info' : const {'params' : 3, 'expr' : false}},
366 const {'name' : 'rotateX', 'info' : const {'params' : 1, 'expr' : false}},
367 const {'name' : 'rotateY', 'info' : const {'params' : 1, 'expr' : false}},
368 const {'name' : 'rotateZ', 'info' : const {'params' : 1, 'expr' : false}},
369 const {'name' : 'perspective',
370 'info' : const {'params' : 1, 'expr' : false}},
371 ];
372
373 List<int> tokens;
374
375 /*
376 * Return the token that matches the unit ident found.
377 */
378 static int matchList(var identList, String tokenField, String text,
379 int offset, int length) {
380 for (final entry in identList) {
381 String ident = entry['value'];
382 if (length == ident.length) {
383 int idx = offset;
384 bool match = true;
385 for (int identIdx = 0; identIdx < ident.length; identIdx++) {
386 int identChar = ident.codeUnitAt(identIdx);
387 int char = text.codeUnitAt(idx++);
388 // Compare lowercase to lowercase then check if char is uppercase.
389 match = match && (char == identChar ||
390 ((char >= ASCII_UPPER_A && char <= ASCII_UPPER_Z) &&
391 (char + 32) == identChar));
392 if (!match) {
393 break;
394 }
395 }
396
397 if (match) {
398 // Completely matched; return the token for this unit.
399 return entry[tokenField];
400 }
401 }
402 }
403
404 return -1; // Not a unit token.
405 }
406
407 /*
408 * Return the token that matches the unit ident found.
409 */
410 static int matchUnits(String text, int offset, int length) {
411 return matchList(_UNITS, 'unit', text, offset, length);
412 }
413
414 /*
415 * Return the token that matches the directive ident found.
416 */
417 static int matchDirectives(String text, int offset, int length) {
418 return matchList(_DIRECTIVES, 'type', text, offset, length);
419 }
420
421 /*
422 * Return the unit token as its pretty name.
423 */
424 static String unitToString(int unitTokenToFind) {
425 if (unitTokenToFind == TokenKind.PERCENT) {
426 return '%';
427 } else {
428 for (final entry in _UNITS) {
429 int unit = entry['unit'];
430 if (unit == unitTokenToFind) {
431 return entry['value'];
432 }
433 }
434 }
435
436 return '<BAD UNIT>'; // Not a unit token.
437 }
438
439 /*
440 * Match color name, case insensitive match and return the associated RGB
441 * value as decimal number.
442 */
443 static int matchColorName(String text) {
444 int length = text.length;
445 for (final entry in _EXTENDED_COLOR_NAMES) {
446 String ident = entry['name'];
447 if (length == ident.length) {
448 int idx = 0;
449 bool match = true;
450 for (int identIdx = 0; identIdx < ident.length; identIdx++) {
451 int identChar = ident.codeUnitAt(identIdx);
452 int char = text.codeUnitAt(idx++);
453 // Compare lowercase to lowercase then check if char is uppercase.
454 match = match && (char == identChar ||
455 ((char >= ASCII_UPPER_A && char <= ASCII_UPPER_Z) &&
456 (char + 32) == identChar));
457 if (!match) {
458 break;
459 }
460 }
461
462 if (match) {
463 // Completely matched; return the token for this unit.
464 return entry['value'];
465 }
466 }
467 }
468
469 // No match.
470 throw new NoColorMatchException(text);
471 }
472
473 static String decimalToHex(int num, [int minDigits = 1]) {
474 final String _HEX_DIGITS = '0123456789abcdef';
475
476 List<String> result = new List<String>();
477
478 int dividend = num >> 4;
479 int remain = num % 16;
480 result.add(_HEX_DIGITS[remain]);
481 while (dividend != 0) {
482 remain = dividend % 16;
483 dividend >>= 4;
484 result.add(_HEX_DIGITS[remain]);
485 }
486
487 StringBuffer invertResult = new StringBuffer();
488 int paddings = minDigits - result.length;
489 while (paddings-- > 0) {
490 invertResult.write('0');
491 }
492 for (int idx = result.length - 1; idx >= 0; idx--) {
493 invertResult.write(result[idx]);
494 }
495
496 return invertResult.toString();
497 }
498
499 static String kindToString(int kind) {
500 switch(kind) {
501 case TokenKind.UNUSED: return "ERROR";
502 case TokenKind.END_OF_FILE: return "end of file";
503 case TokenKind.LPAREN: return "(";
504 case TokenKind.RPAREN: return ")";
505 case TokenKind.LBRACK: return "[";
506 case TokenKind.RBRACK: return "]";
507 case TokenKind.LBRACE: return "{";
508 case TokenKind.RBRACE: return "}";
509 case TokenKind.DOT: return ".";
510 case TokenKind.SEMICOLON: return ";";
511 case TokenKind.AT: return "@";
512 case TokenKind.HASH: return "#";
513 case TokenKind.PLUS: return "+";
514 case TokenKind.GREATER: return ">";
515 case TokenKind.TILDE: return "~";
516 case TokenKind.ASTERISK: return "*";
517 case TokenKind.NAMESPACE: return "|";
518 case TokenKind.COLON: return ":";
519 case TokenKind.PRIVATE_NAME: return "_";
520 case TokenKind.COMMA: return ",";
521 case TokenKind.SPACE: return " ";
522 case TokenKind.TAB: return "\t";
523 case TokenKind.NEWLINE: return "\n";
524 case TokenKind.RETURN: return "\r";
525 case TokenKind.PERCENT: return "%";
526 case TokenKind.SINGLE_QUOTE: return "'";
527 case TokenKind.DOUBLE_QUOTE: return "\"";
528 case TokenKind.SLASH: return "/";
529 case TokenKind.EQUALS: return '=';
530 case TokenKind.OR: return '|';
531 case TokenKind.CARET: return '^';
532 case TokenKind.DOLLAR: return '\$';
533 case TokenKind.LESS: return '<';
534 case TokenKind.BANG: return '!';
535 case TokenKind.MINUS: return '-';
536
537 default:
538 throw "Unknown TOKEN";
539 }
540 }
541
542 TokenKind() {
543 tokens = [];
544
545 // All tokens must be in TokenKind order.
546 tokens.add(-1); // TokenKind.UNUSED
547 tokens.add(0); // TokenKind.END_OF_FILE match base
548 tokens.add(TokenKind.kindToString(TokenKind.LPAREN).codeUnitAt(0));
549 tokens.add(TokenKind.kindToString(TokenKind.RPAREN).codeUnitAt(0));
550 tokens.add(TokenKind.kindToString(TokenKind.LBRACK).codeUnitAt(0));
551 tokens.add(TokenKind.kindToString(TokenKind.RBRACK).codeUnitAt(0));
552 tokens.add(TokenKind.kindToString(TokenKind.LBRACE).codeUnitAt(0));
553 tokens.add(TokenKind.kindToString(TokenKind.RBRACE).codeUnitAt(0));
554 tokens.add(TokenKind.kindToString(TokenKind.DOT).codeUnitAt(0));
555 tokens.add(TokenKind.kindToString(TokenKind.SEMICOLON).codeUnitAt(0));
556 tokens.add(TokenKind.kindToString(TokenKind.AT).codeUnitAt(0));
557 tokens.add(TokenKind.kindToString(TokenKind.HASH).codeUnitAt(0));
558 tokens.add(TokenKind.kindToString(TokenKind.PLUS).codeUnitAt(0));
559 tokens.add(TokenKind.kindToString(TokenKind.GREATER).codeUnitAt(0));
560 tokens.add(TokenKind.kindToString(TokenKind.TILDE).codeUnitAt(0));
561 tokens.add(TokenKind.kindToString(TokenKind.ASTERISK).codeUnitAt(0));
562 tokens.add(TokenKind.kindToString(TokenKind.NAMESPACE).codeUnitAt(0));
563 tokens.add(TokenKind.kindToString(TokenKind.COLON).codeUnitAt(0));
564 tokens.add(TokenKind.kindToString(TokenKind.PRIVATE_NAME).codeUnitAt(0));
565 tokens.add(TokenKind.kindToString(TokenKind.COMMA).codeUnitAt(0));
566 tokens.add(TokenKind.kindToString(TokenKind.SPACE).codeUnitAt(0));
567 tokens.add(TokenKind.kindToString(TokenKind.TAB).codeUnitAt(0));
568 tokens.add(TokenKind.kindToString(TokenKind.NEWLINE).codeUnitAt(0));
569 tokens.add(TokenKind.kindToString(TokenKind.RETURN).codeUnitAt(0));
570 tokens.add(TokenKind.kindToString(TokenKind.PERCENT).codeUnitAt(0));
571 tokens.add(TokenKind.kindToString(TokenKind.SINGLE_QUOTE).codeUnitAt(0));
572 tokens.add(TokenKind.kindToString(TokenKind.DOUBLE_QUOTE).codeUnitAt(0));
573 tokens.add(TokenKind.kindToString(TokenKind.SLASH).codeUnitAt(0));
574 tokens.add(TokenKind.kindToString(TokenKind.EQUALS).codeUnitAt(0));
575 tokens.add(TokenKind.kindToString(TokenKind.OR).codeUnitAt(0));
576 tokens.add(TokenKind.kindToString(TokenKind.CARET).codeUnitAt(0));
577 tokens.add(TokenKind.kindToString(TokenKind.DOLLAR).codeUnitAt(0));
578 tokens.add(TokenKind.kindToString(TokenKind.LESS).codeUnitAt(0));
579 tokens.add(TokenKind.kindToString(TokenKind.BANG).codeUnitAt(0));
580 tokens.add(TokenKind.kindToString(TokenKind.MINUS).codeUnitAt(0));
581
582 assert(tokens.length == TokenKind.END_TOKENS);
583 }
584
585 static bool isIdentifier(int kind) {
586 return kind == IDENTIFIER ;
587 }
588
589 }
590
591 class NoColorMatchException implements Exception {
592 String _colorName;
593 NoColorMatchException(this._colorName);
594
595 String get name => _colorName;
596 }
OLDNEW
« no previous file with comments | « utils/css/tokenizer_base.dart ('k') | utils/css/tool.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698