OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // TODO(terry): Need to be consistent with tokens either they're ASCII tokens | 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_*. | 6 // e.g., ASTERISK or they're CSS e.g., PSEUDO, COMBINATOR_*. |
7 class TokenKind { | 7 class TokenKind { |
8 // Common shared tokens used in TokenizerBase. | 8 // Common shared tokens used in TokenizerBase. |
9 static final int END_OF_FILE = 0; | 9 static final int UNUSED = 0; // Unused place holder... |
10 static final int LPAREN = 1; | 10 static final int END_OF_FILE = 1; // TODO(terry): Must match base |
11 static final int RPAREN = 2; | 11 static final int LPAREN = 2; // ( |
12 static final int LBRACK = 3; | 12 static final int RPAREN = 3; // ) |
13 static final int RBRACK = 4; | 13 static final int LBRACK = 4; // [ |
14 static final int LBRACE = 5; | 14 static final int RBRACK = 5; // ] |
15 static final int RBRACE = 6; | 15 static final int LBRACE = 6; // { |
16 static final int DOT = 7; | 16 static final int RBRACE = 7; // } |
| 17 static final int DOT = 8; // . |
| 18 static final int SEMICOLON = 9; // ; |
17 | 19 |
18 // Unique tokens for CSS. | 20 // Unique tokens for CSS. |
19 static final int AT = 8; | 21 static final int AT = 10; // @ |
20 static final int HASH = 9; | 22 static final int HASH = 11; // # |
21 static final int COMBINATOR_PLUS = 10; | 23 static final int PLUS = 12; // + |
22 static final int COMBINATOR_GREATER = 11; | 24 static final int GREATER = 13; // > |
23 static final int COMBINATOR_TILDE = 12; | 25 static final int TILDE = 14; // ~ |
24 static final int ASTERISK = 13; | 26 static final int ASTERISK = 15; // * |
25 static final int NAMESPACE = 14; | 27 static final int NAMESPACE = 16; // | |
26 static final int PSEUDO = 15; | 28 static final int COLON = 17; // : |
27 static final int PRIVATE_NAME = 16; // _ prefix private class or id | 29 static final int PRIVATE_NAME = 18; // _ prefix private class or id |
28 static final int COMMA = 17; | 30 static final int COMMA = 19; // , |
29 static final int SPACE = 18; | 31 static final int SPACE = 20; |
30 static final int TAB = 19; | 32 static final int TAB = 21; // /t |
31 static final int NEWLINE = 20; | 33 static final int NEWLINE = 22; // /n |
32 static final int RETURN = 21; | 34 static final int RETURN = 23; // /r |
| 35 static final int PERCENT = 24; // % |
| 36 static final int SINGLE_QUOTE = 25; // ' |
| 37 static final int DOUBLE_QUOTE = 26; // " |
| 38 static final int SLASH = 27; // / |
| 39 static final int EQUALS = 28; // = |
| 40 static final int OR = 29; // | |
| 41 static final int CARET = 30; // ^ |
| 42 static final int DOLLAR = 31; // $ |
| 43 static final int LESS = 32; // < |
| 44 static final int BANG = 33; // ! |
| 45 static final int MINUS = 34; // - |
33 | 46 |
34 // WARNING: END_TOKENS must be 1 greater than the last token above (last | 47 // WARNING: END_TOKENS must be 1 greater than the last token above (last |
35 // character in our list). Also add to kindToString function and the | 48 // character in our list). Also add to kindToString function and the |
36 // constructor for TokenKind. | 49 // constructor for TokenKind. |
37 | 50 |
38 static final int END_TOKENS = 22; // Marker for last token in list | 51 static final int END_TOKENS = 35; // Marker for last token in list |
| 52 |
| 53 /** [TokenKind] representing integer tokens. */ |
| 54 static final int INTEGER = 60; // TODO(terry): must match base |
| 55 |
| 56 /** [TokenKind] representing hex integer tokens. */ |
| 57 // static final int HEX_INTEGER = 61; // TODO(terry): must match bas
e |
| 58 |
| 59 /** [TokenKind] representing double tokens. */ |
| 60 static final int DOUBLE = 62; // TODO(terry): must match base |
| 61 |
| 62 /** [TokenKind] representing whitespace tokens. */ |
| 63 static final int WHITESPACE = 63; // TODO(terry): must match base |
| 64 |
| 65 /** [TokenKind] representing comment tokens. */ |
| 66 static final int COMMENT = 64; // TODO(terry): must match base |
| 67 |
| 68 /** [TokenKind] representing error tokens. */ |
| 69 static final int ERROR = 65; // TODO(terry): must match base |
| 70 |
| 71 /** [TokenKind] representing incomplete string tokens. */ |
| 72 static final int INCOMPLETE_STRING = 66; // TODO(terry): must match base |
| 73 |
| 74 /** [TokenKind] representing incomplete comment tokens. */ |
| 75 static final int INCOMPLETE_COMMENT = 67; // TODO(terry): must match base |
39 | 76 |
40 // Synthesized Tokens (no character associated with TOKEN). | 77 // Synthesized Tokens (no character associated with TOKEN). |
41 // TODO(terry): Possible common names used by both Dart and CSS tokenizers. | 78 // TODO(terry): Possible common names used by both Dart and CSS tokenizers. |
42 static final int STRING = 500; | 79 static final int STRING = 500; |
43 static final int STRING_PART = 501; | 80 static final int STRING_PART = 501; |
44 static final int NUMBER = 502; | 81 static final int NUMBER = 502; |
45 static final int HEX_NUMBER = 503; | 82 static final int HEX_NUMBER = 503; |
46 static final int WHITESPACE = 504; | 83 static final int HTML_COMMENT = 504; // <!-- |
47 static final int COMMENT = 505; | 84 static final int IMPORTANT = 505; // !important |
48 static final int ERROR = 506; | |
49 static final int INCOMPLETE_STRING = 507; | |
50 static final int INCOMPLETE_COMMENT = 508; | |
51 static final int INCOMPLETE_MULTILINE_STRING_DQ = 509; | |
52 static final int INCOMPLETE_MULTILINE_STRING_SQ = 510; | |
53 static final int IDENTIFIER = 511; | 85 static final int IDENTIFIER = 511; |
54 | 86 |
55 // Uniquely synthesized tokens for CSS. | 87 // Uniquely synthesized tokens for CSS. |
56 static final int SELECTOR_EXPRESSION = 512; | 88 static final int SELECTOR_EXPRESSION = 512; |
57 static final int COMBINATOR_NONE = 513; | 89 static final int COMBINATOR_NONE = 513; |
58 static final int COMBINATOR_DESCENDANT = 514; // Space combinator | 90 static final int COMBINATOR_DESCENDANT = 514; // Space combinator |
| 91 static final int COMBINATOR_PLUS = 515; // + combinator |
| 92 static final int COMBINATOR_GREATER = 516; // > combinator |
| 93 static final int COMBINATOR_TILDE = 517; // ~ combinator |
59 | 94 |
60 // Attribute match: | 95 static final int UNARY_OP_NONE = 518; // No unary operator present. |
61 static final int INCLUDES_MATCH = 515; // ~= | 96 |
62 static final int DASH_MATCH = 516; // |= | 97 // Attribute match types: |
63 static final int PREFIX_MATCH = 517; // ^= | 98 static final int INCLUDES = 530; // '~=' |
64 static final int SUFFIX_MATCH = 518; // $= | 99 static final int DASH_MATCH = 531; // '|=' |
65 static final int STRING_MATCH = 519; // *= | 100 static final int PREFIX_MATCH = 532; // '^=' |
66 static final int EQUAL_MATCH = 520; // = | 101 static final int SUFFIX_MATCH = 533; // '$=' |
| 102 static final int SUBSTRING_MATCH = 534; // '*=' |
| 103 static final int NO_MATCH = 535; // No operator. |
| 104 |
| 105 // Unit types: |
| 106 static final int UNIT_EM = 600; |
| 107 static final int UNIT_EX = 601; |
| 108 static final int UNIT_LENGTH_PX = 602; |
| 109 static final int UNIT_LENGTH_CM = 603; |
| 110 static final int UNIT_LENGTH_MM = 604; |
| 111 static final int UNIT_LENGTH_IN = 605; |
| 112 static final int UNIT_LENGTH_PT = 606; |
| 113 static final int UNIT_LENGTH_PC = 607; |
| 114 static final int UNIT_ANGLE_DEG = 608; |
| 115 static final int UNIT_ANGLE_RAD = 609; |
| 116 static final int UNIT_ANGLE_GRAD = 610; |
| 117 static final int UNIT_TIME_MS = 611; |
| 118 static final int UNIT_TIME_S = 612; |
| 119 static final int UNIT_FREQ_HZ = 613; |
| 120 static final int UNIT_FREQ_KHZ = 614; |
| 121 static final int UNIT_PERCENT = 615; |
| 122 static final int UNIT_FRACTION = 616; |
| 123 |
| 124 // Directives (@nnnn) |
| 125 static final int DIRECTIVE_NONE = 650; |
| 126 static final int DIRECTIVE_IMPORT = 651; |
| 127 static final int DIRECTIVE_MEDIA = 652; |
| 128 static final int DIRECTIVE_PAGE = 653; |
| 129 static final int DIRECTIVE_INCLUDE = 654; |
| 130 static final int DIRECTIVE_STYLET = 655; |
| 131 static final int DIRECTIVE_KEYFRAMES = 656; |
| 132 static final int DIRECTIVE_FONTFACE = 657; |
67 | 133 |
68 // Simple selector type. | 134 // Simple selector type. |
69 static final int CLASS_NAME = 700; // .class | 135 static final int CLASS_NAME = 700; // .class |
70 static final int ELEMENT_NAME = 701; // tagName | 136 static final int ELEMENT_NAME = 701; // tagName |
71 static final int HASH_NAME = 702; // #elementId | 137 static final int HASH_NAME = 702; // #elementId |
72 static final int ATTRIBUTE_NAME = 703; // [attrib] | 138 static final int ATTRIBUTE_NAME = 703; // [attrib] |
73 static final int PSEUDO_ELEMENT_NAME = 704; // ::pseudoElement | 139 static final int PSEUDO_ELEMENT_NAME = 704; // ::pseudoElement |
74 static final int PSEUDO_CLASS_NAME = 705; // :pseudoClass | 140 static final int PSEUDO_CLASS_NAME = 705; // :pseudoClass |
75 static final int NEGATION = 706; // NOT | 141 static final int NEGATION = 706; // NOT |
76 | 142 |
| 143 static final 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 final 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 final int ASCII_UPPER_A = 65; // ASCII value for uppercase A |
| 174 static final int ASCII_UPPER_Z = 90; // ASCII value for uppercase Z |
| 175 |
| 176 // Extended color keywords: |
| 177 static final 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 final 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 |
77 List<int> tokens; | 373 List<int> tokens; |
78 | 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 (var entry in identList) { |
| 381 String ident = entry['value']; |
| 382 if (length == ident.length) { |
| 383 int idx = offset; |
| 384 bool match = true; |
| 385 for (var identIdx = 0; identIdx < ident.length; identIdx++) { |
| 386 int identChar = ident.charCodeAt(identIdx); |
| 387 int char = text.charCodeAt(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 (var 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 (var 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 (var identIdx = 0; identIdx < ident.length; identIdx++) { |
| 451 int identChar = ident.charCodeAt(identIdx); |
| 452 int char = text.charCodeAt(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) { |
| 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 for (var idx = result.length - 1; idx >= 0; idx--) { |
| 489 invertResult.add(result[idx]); |
| 490 } |
| 491 return invertResult.toString(); |
| 492 } |
| 493 |
79 static String kindToString(int kind) { | 494 static String kindToString(int kind) { |
80 switch(kind) { | 495 switch(kind) { |
| 496 case TokenKind.UNUSED: return "ERROR"; |
81 case TokenKind.END_OF_FILE: return "end of file"; | 497 case TokenKind.END_OF_FILE: return "end of file"; |
82 case TokenKind.LPAREN: return "("; | 498 case TokenKind.LPAREN: return "("; |
83 case TokenKind.RPAREN: return ")"; | 499 case TokenKind.RPAREN: return ")"; |
84 case TokenKind.LBRACK: return "["; | 500 case TokenKind.LBRACK: return "["; |
85 case TokenKind.RBRACK: return "["; | 501 case TokenKind.RBRACK: return "]"; |
86 case TokenKind.LBRACE: return "{"; | 502 case TokenKind.LBRACE: return "{"; |
87 case TokenKind.RBRACE: return "}"; | 503 case TokenKind.RBRACE: return "}"; |
88 case TokenKind.DOT: return "."; | 504 case TokenKind.DOT: return "."; |
| 505 case TokenKind.SEMICOLON: return ";"; |
89 case TokenKind.AT: return "@"; | 506 case TokenKind.AT: return "@"; |
90 case TokenKind.HASH: return "#"; | 507 case TokenKind.HASH: return "#"; |
91 case TokenKind.COMBINATOR_PLUS: return "+"; | 508 case TokenKind.PLUS: return "+"; |
92 case TokenKind.COMBINATOR_GREATER: return ">"; | 509 case TokenKind.GREATER: return ">"; |
93 case TokenKind.COMBINATOR_TILDE: return "~"; | 510 case TokenKind.TILDE: return "~"; |
94 case TokenKind.ASTERISK: return "*"; | 511 case TokenKind.ASTERISK: return "*"; |
95 case TokenKind.NAMESPACE: return "|"; | 512 case TokenKind.NAMESPACE: return "|"; |
96 case TokenKind.PSEUDO: return ":"; | 513 case TokenKind.COLON: return ":"; |
97 case TokenKind.PRIVATE_NAME: return "_"; | 514 case TokenKind.PRIVATE_NAME: return "_"; |
98 case TokenKind.COMMA: return ","; | 515 case TokenKind.COMMA: return ","; |
99 case TokenKind.SPACE: return " "; | 516 case TokenKind.SPACE: return " "; |
100 case TokenKind.TAB: return "\t"; | 517 case TokenKind.TAB: return "\t"; |
101 case TokenKind.NEWLINE: return "\n"; | 518 case TokenKind.NEWLINE: return "\n"; |
102 case TokenKind.RETURN: return "\r"; | 519 case TokenKind.RETURN: return "\r"; |
| 520 case TokenKind.PERCENT: return "%"; |
| 521 case TokenKind.SINGLE_QUOTE: return "'"; |
| 522 case TokenKind.DOUBLE_QUOTE: return "\""; |
| 523 case TokenKind.SLASH: return "/"; |
| 524 case TokenKind.EQUALS: return '='; |
| 525 case TokenKind.OR: return '|'; |
| 526 case TokenKind.CARET: return '^'; |
| 527 case TokenKind.DOLLAR: return '\$'; |
| 528 case TokenKind.LESS: return '<'; |
| 529 case TokenKind.BANG: return '!'; |
| 530 case TokenKind.MINUS: return '-'; |
103 | 531 |
104 default: | 532 default: |
105 throw "Unknown TOKEN"; | 533 throw "Unknown TOKEN"; |
106 } | 534 } |
107 } | 535 } |
108 | 536 |
109 TokenKind() { | 537 TokenKind() { |
110 tokens = []; | 538 tokens = []; |
111 | 539 |
112 // All tokens must be in TokenKind order. | 540 // All tokens must be in TokenKind order. |
113 tokens.add(0); // TokenKind.END_OF_FILE | 541 tokens.add(-1); // TokenKind.UNUSED |
| 542 tokens.add(0); // TokenKind.END_OF_FILE match base |
114 tokens.add(TokenKind.kindToString(TokenKind.LPAREN).charCodeAt(0)); | 543 tokens.add(TokenKind.kindToString(TokenKind.LPAREN).charCodeAt(0)); |
115 tokens.add(TokenKind.kindToString(TokenKind.RPAREN).charCodeAt(0)); | 544 tokens.add(TokenKind.kindToString(TokenKind.RPAREN).charCodeAt(0)); |
116 tokens.add(TokenKind.kindToString(TokenKind.LBRACK).charCodeAt(0)); | 545 tokens.add(TokenKind.kindToString(TokenKind.LBRACK).charCodeAt(0)); |
117 tokens.add(TokenKind.kindToString(TokenKind.RBRACK).charCodeAt(0)); | 546 tokens.add(TokenKind.kindToString(TokenKind.RBRACK).charCodeAt(0)); |
118 tokens.add(TokenKind.kindToString(TokenKind.LBRACE).charCodeAt(0)); | 547 tokens.add(TokenKind.kindToString(TokenKind.LBRACE).charCodeAt(0)); |
119 tokens.add(TokenKind.kindToString(TokenKind.RBRACE).charCodeAt(0)); | 548 tokens.add(TokenKind.kindToString(TokenKind.RBRACE).charCodeAt(0)); |
120 tokens.add(TokenKind.kindToString(TokenKind.DOT).charCodeAt(0)); | 549 tokens.add(TokenKind.kindToString(TokenKind.DOT).charCodeAt(0)); |
| 550 tokens.add(TokenKind.kindToString(TokenKind.SEMICOLON).charCodeAt(0)); |
121 tokens.add(TokenKind.kindToString(TokenKind.AT).charCodeAt(0)); | 551 tokens.add(TokenKind.kindToString(TokenKind.AT).charCodeAt(0)); |
122 tokens.add(TokenKind.kindToString(TokenKind.HASH).charCodeAt(0)); | 552 tokens.add(TokenKind.kindToString(TokenKind.HASH).charCodeAt(0)); |
123 tokens.add(TokenKind.kindToString(TokenKind.COMBINATOR_PLUS).charCodeAt(0)); | 553 tokens.add(TokenKind.kindToString(TokenKind.PLUS).charCodeAt(0)); |
124 tokens.add(TokenKind.kindToString(TokenKind.COMBINATOR_GREATER).charCodeAt(0
)); | 554 tokens.add(TokenKind.kindToString(TokenKind.GREATER).charCodeAt(0)); |
125 tokens.add(TokenKind.kindToString(TokenKind.COMBINATOR_TILDE).charCodeAt(0))
; | 555 tokens.add(TokenKind.kindToString(TokenKind.TILDE).charCodeAt(0)); |
126 tokens.add(TokenKind.kindToString(TokenKind.ASTERISK).charCodeAt(0)); | 556 tokens.add(TokenKind.kindToString(TokenKind.ASTERISK).charCodeAt(0)); |
127 tokens.add(TokenKind.kindToString(TokenKind.NAMESPACE).charCodeAt(0)); | 557 tokens.add(TokenKind.kindToString(TokenKind.NAMESPACE).charCodeAt(0)); |
128 tokens.add(TokenKind.kindToString(TokenKind.PSEUDO).charCodeAt(0)); | 558 tokens.add(TokenKind.kindToString(TokenKind.COLON).charCodeAt(0)); |
129 tokens.add(TokenKind.kindToString(TokenKind.PRIVATE_NAME).charCodeAt(0)); | 559 tokens.add(TokenKind.kindToString(TokenKind.PRIVATE_NAME).charCodeAt(0)); |
130 tokens.add(TokenKind.kindToString(TokenKind.COMMA).charCodeAt(0)); | 560 tokens.add(TokenKind.kindToString(TokenKind.COMMA).charCodeAt(0)); |
131 tokens.add(TokenKind.kindToString(TokenKind.SPACE).charCodeAt(0)); | 561 tokens.add(TokenKind.kindToString(TokenKind.SPACE).charCodeAt(0)); |
132 tokens.add(TokenKind.kindToString(TokenKind.TAB).charCodeAt(0)); | 562 tokens.add(TokenKind.kindToString(TokenKind.TAB).charCodeAt(0)); |
133 tokens.add(TokenKind.kindToString(TokenKind.NEWLINE).charCodeAt(0)); | 563 tokens.add(TokenKind.kindToString(TokenKind.NEWLINE).charCodeAt(0)); |
134 tokens.add(TokenKind.kindToString(TokenKind.RETURN).charCodeAt(0)); | 564 tokens.add(TokenKind.kindToString(TokenKind.RETURN).charCodeAt(0)); |
| 565 tokens.add(TokenKind.kindToString(TokenKind.PERCENT).charCodeAt(0)); |
| 566 tokens.add(TokenKind.kindToString(TokenKind.SINGLE_QUOTE).charCodeAt(0)); |
| 567 tokens.add(TokenKind.kindToString(TokenKind.DOUBLE_QUOTE).charCodeAt(0)); |
| 568 tokens.add(TokenKind.kindToString(TokenKind.SLASH).charCodeAt(0)); |
| 569 tokens.add(TokenKind.kindToString(TokenKind.EQUALS).charCodeAt(0)); |
| 570 tokens.add(TokenKind.kindToString(TokenKind.OR).charCodeAt(0)); |
| 571 tokens.add(TokenKind.kindToString(TokenKind.CARET).charCodeAt(0)); |
| 572 tokens.add(TokenKind.kindToString(TokenKind.DOLLAR).charCodeAt(0)); |
| 573 tokens.add(TokenKind.kindToString(TokenKind.LESS).charCodeAt(0)); |
| 574 tokens.add(TokenKind.kindToString(TokenKind.BANG).charCodeAt(0)); |
| 575 tokens.add(TokenKind.kindToString(TokenKind.MINUS).charCodeAt(0)); |
135 | 576 |
136 assert(tokens.length == TokenKind.END_TOKENS); | 577 assert(tokens.length == TokenKind.END_TOKENS); |
137 } | 578 } |
138 | 579 |
139 static bool isIdentifier(int kind) { | 580 static bool isIdentifier(int kind) { |
140 return kind == IDENTIFIER ; | 581 return kind == IDENTIFIER ; |
141 } | 582 } |
| 583 |
142 } | 584 } |
| 585 |
| 586 class NoColorMatchException implements Exception { |
| 587 String _colorName; |
| 588 NoColorMatchException(this._colorName); |
| 589 |
| 590 String get name() => _colorName; |
| 591 } |
OLD | NEW |