OLD | NEW |
(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 final int UNUSED = 0; // Unused place holder... |
| 10 static final int END_OF_FILE = 1; |
| 11 static final int LPAREN = 2; // ( |
| 12 static final int RPAREN = 3; // ) |
| 13 static final int LBRACK = 4; // [ |
| 14 static final int RBRACK = 5; // ] |
| 15 static final int LBRACE = 6; // { |
| 16 static final int RBRACE = 7; // } |
| 17 static final int DOT = 8; // . |
| 18 static final int SEMICOLON = 9; // ; |
| 19 static final int SPACE = 10; // space character |
| 20 static final int TAB = 11; // \t |
| 21 static final int NEWLINE = 12; // \n |
| 22 static final int RETURN = 13; // \r |
| 23 static final int COMMA = 14; // , |
| 24 |
| 25 // Unique tokens. |
| 26 static final int LESS_THAN = 15; // < |
| 27 static final int GREATER_THAN = 16; // > |
| 28 static final int SLASH = 17; // / |
| 29 static final int DOLLAR = 18; // $ |
| 30 static final int HASH = 19; // # |
| 31 static final int MINUS = 20; // - |
| 32 static final int EQUAL = 21; // = |
| 33 static final int DOUBLE_QUOTE = 22; // " |
| 34 static final int SINGLE_QUOTE = 23; // ' |
| 35 |
| 36 // WARNING: END_TOKENS must be 1 greater than the last token above (last |
| 37 // character in our list). Also add to kindToString function and the |
| 38 // constructor for TokenKind. |
| 39 |
| 40 static final int END_TOKENS = 24; // Marker for last token in list |
| 41 |
| 42 // Synthesized tokens: |
| 43 |
| 44 static final int END_NO_SCOPE_TAG = 50; // /> |
| 45 static final int START_EXPRESSION = 51; // ${ |
| 46 static final int START_COMMAND = 52; // ${# |
| 47 static final int END_COMMAND = 53; // ${/ |
| 48 static final int EACH_COMMAND = 53; // ${#each list} |
| 49 static final int WITH_COMMAND = 54; // ${#with object} |
| 50 static final int IF_COMMAND = 55; // ${#if (expression)} |
| 51 static final int ELSE_COMMAND = 56; // ${#else} |
| 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 base |
| 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 |
| 76 |
| 77 // Synthesized Tokens (no character associated with TOKEN). |
| 78 // TODO(terry): Possible common names used by both Dart and CSS tokenizers. |
| 79 static final int ATTR_VALUE = 500; |
| 80 static final int NUMBER = 502; |
| 81 static final int HEX_NUMBER = 503; |
| 82 static final int HTML_COMMENT = 504; // <!-- |
| 83 static final int IDENTIFIER = 511; |
| 84 static final int STRING = 512; |
| 85 static final int STRING_PART = 513; |
| 86 |
| 87 static final int TEMPLATE_KEYWORD = 595; // template keyword |
| 88 |
| 89 // Elements |
| 90 /* START_HTML_ELEMENT is first valid element tag name |
| 91 * END_HTML_ELEMENT is the last valid element tag name |
| 92 * |
| 93 */ |
| 94 static final int START_HTML_ELEMENT = 600; // First valid tag name. |
| 95 static final int A_ELEMENT = 600; |
| 96 static final int ABBR_ELEMENT = 601; |
| 97 static final int ACRONYM_ELEMENT = 602; |
| 98 static final int ADDRESS_ELEMENT = 603; |
| 99 static final int APPLET_ELEMENT = 604; |
| 100 static final int AREA_ELEMENT = 605; |
| 101 static final int B_ELEMENT = 606; |
| 102 static final int BASE_ELEMENT = 607; |
| 103 static final int BASEFONT_ELEMENT = 608; |
| 104 static final int BDO_ELEMENT = 609; |
| 105 static final int BIG_ELEMENT = 610; |
| 106 static final int BLOCKQUOTE_ELEMENT = 611; |
| 107 static final int BODY_ELEMENT = 612; |
| 108 static final int BR_ELEMENT = 613; |
| 109 static final int BUTTON_ELEMENT = 614; |
| 110 static final int CAPTION_ELEMENT = 615; |
| 111 static final int CENTER_ELEMENT = 616; |
| 112 static final int CITE_ELEMENT = 617; |
| 113 static final int CODE_ELEMENT = 618; |
| 114 static final int COL_ELEMENT = 619; |
| 115 static final int COLGROUP_ELEMENT = 620; |
| 116 static final int DD_ELEMENT = 621; |
| 117 static final int DEL_ELEMENT = 622; |
| 118 static final int DFN_ELEMENT = 623; |
| 119 static final int DIR_ELEMENT = 624; |
| 120 static final int DIV_ELEMENT = 625; |
| 121 static final int DL_ELEMENT = 626; |
| 122 static final int DT_ELEMENT = 627; |
| 123 static final int EM_ELEMENT = 628; |
| 124 static final int FIELDSET_ELEMENT = 629; |
| 125 static final int FONT_ELEMENT = 630; |
| 126 static final int FORM_ELEMENT = 631; |
| 127 static final int FRAME_ELEMENT = 632; |
| 128 static final int FRAMESET_ELEMENT = 633; |
| 129 static final int H1_ELEMENT = 634; |
| 130 static final int H2_ELEMENT = 635; |
| 131 static final int H3_ELEMENT = 636; |
| 132 static final int H4_ELEMENT = 637; |
| 133 static final int H5_ELEMENT = 638; |
| 134 static final int H6_ELEMENT = 639; |
| 135 static final int HEAD_ELEMENT = 640; |
| 136 static final int HR_ELEMENT = 641; |
| 137 static final int HTML_ELEMENT = 642; |
| 138 static final int I_ELEMENT = 643; |
| 139 static final int IFRAME_ELEMENT = 644; |
| 140 static final int IMG_ELEMENT = 645; |
| 141 static final int INPUT_ELEMENT = 646; |
| 142 static final int INS_ELEMENT = 647; |
| 143 static final int ISINDEX_ELEMENT = 648; |
| 144 static final int KBD_ELEMENT = 649; |
| 145 static final int LABEL_ELEMENT = 650; |
| 146 static final int LEGEND_ELEMENT = 651; |
| 147 static final int LI_ELEMENT = 652; |
| 148 static final int LINK_ELEMENT = 653; |
| 149 static final int MAP_ELEMENT = 654; |
| 150 static final int MENU_ELEMENT = 645; |
| 151 static final int META_ELEMENT = 656; |
| 152 static final int NOFRAMES_ELEMENT = 657; |
| 153 static final int NOSCRIPT_ELEMENT = 658; |
| 154 static final int OBJECT_ELEMENT = 659; |
| 155 static final int OL_ELEMENT = 660; |
| 156 static final int OPTGROUP_ELEMENT = 661; |
| 157 static final int OPTION_ELEMENT = 662; |
| 158 static final int P_ELEMENT = 663; |
| 159 static final int PARAM_ELEMENT = 664; |
| 160 static final int PRE_ELEMENT = 665; |
| 161 static final int Q_ELEMENT = 666; |
| 162 static final int S_ELEMENT = 667; |
| 163 static final int SAMP_ELEMENT = 668; |
| 164 static final int SCRIPT_ELEMENT = 669; |
| 165 static final int SELECT_ELEMENT = 670; |
| 166 static final int SMALL_ELEMENT = 671; |
| 167 static final int SPAN_ELEMENT = 672; |
| 168 static final int STRIKE_ELEMENT = 673; |
| 169 static final int STRONG_ELEMENT = 674; |
| 170 static final int STYLE_ELEMENT = 675; |
| 171 static final int SUB_ELEMENT = 676; |
| 172 static final int SUP_ELEMENT = 677; |
| 173 static final int TABLE_ELEMENT = 678; |
| 174 static final int TBODY_ELEMENT = 679; |
| 175 static final int TD_ELEMENT = 680; |
| 176 static final int TEXTAREA_ELEMENT = 681; |
| 177 static final int TFOOT_ELEMENT = 682; |
| 178 static final int TH_ELEMENT = 683; |
| 179 static final int THEAD_ELEMENT = 684; |
| 180 static final int TITLE_ELEMENT = 685; |
| 181 static final int TR_ELEMENT = 686; |
| 182 static final int TT_ELEMENT = 687; |
| 183 static final int U_ELEMENT = 688; |
| 184 static final int UL_ELEMENT = 689; |
| 185 static final int VAR_ELEMENT = 690; |
| 186 static final int END_HTML_ELEMENT = VAR_ELEMENT; // Last valid tag name. |
| 187 |
| 188 static bool validTagName(int tokId) { |
| 189 return tokId >= TokenKind.START_HTML_ELEMENT && |
| 190 tokId <= TokenKind.END_HTML_ELEMENT; |
| 191 } |
| 192 |
| 193 static final List<Map<int, String>> _KEYWORDS = const [ |
| 194 const {'type': TokenKind.TEMPLATE_KEYWORD, 'value' : 'template'}, |
| 195 ]; |
| 196 |
| 197 static final List<Map<int, String>> _ELEMENTS = const [ |
| 198 const {'type': TokenKind.A_ELEMENT, 'value' : 'a'}, |
| 199 const {'type': TokenKind.ABBR_ELEMENT, 'value' : 'abbr'}, |
| 200 const {'type': TokenKind.ACRONYM_ELEMENT, 'value' : 'acronym'}, |
| 201 const {'type': TokenKind.ADDRESS_ELEMENT, 'value' : 'address'}, |
| 202 const {'type': TokenKind.APPLET_ELEMENT, 'value' : 'applet'}, |
| 203 const {'type': TokenKind.AREA_ELEMENT, 'value' : 'area'}, |
| 204 const {'type': TokenKind.B_ELEMENT, 'value' : 'b'}, |
| 205 const {'type': TokenKind.BASE_ELEMENT, 'value' : 'base'}, |
| 206 const {'type': TokenKind.BASEFONT_ELEMENT, 'value' : 'basefont'}, |
| 207 const {'type': TokenKind.BDO_ELEMENT, 'value' : 'bdo'}, |
| 208 const {'type': TokenKind.BIG_ELEMENT, 'value' : 'big'}, |
| 209 const {'type': TokenKind.BLOCKQUOTE_ELEMENT, 'value' : 'blockquote'}, |
| 210 const {'type': TokenKind.BODY_ELEMENT, 'value' : 'body'}, |
| 211 const {'type': TokenKind.BR_ELEMENT, 'value' : 'br'}, |
| 212 const {'type': TokenKind.BUTTON_ELEMENT, 'value' : 'button'}, |
| 213 const {'type': TokenKind.CAPTION_ELEMENT, 'value' : 'caption'}, |
| 214 const {'type': TokenKind.CENTER_ELEMENT, 'value' : 'center'}, |
| 215 const {'type': TokenKind.CITE_ELEMENT, 'value' : 'cite'}, |
| 216 const {'type': TokenKind.CODE_ELEMENT, 'value' : 'code'}, |
| 217 const {'type': TokenKind.COL_ELEMENT, 'value' : 'col'}, |
| 218 const {'type': TokenKind.COLGROUP_ELEMENT, 'value' : 'colgroup'}, |
| 219 const {'type': TokenKind.DD_ELEMENT, 'value' : 'dd'}, |
| 220 const {'type': TokenKind.DEL_ELEMENT, 'value' : 'del'}, |
| 221 const {'type': TokenKind.DFN_ELEMENT, 'value' : 'dfn'}, |
| 222 const {'type': TokenKind.DIR_ELEMENT, 'value' : 'dir'}, |
| 223 const {'type': TokenKind.DIV_ELEMENT, 'value' : 'div'}, |
| 224 const {'type': TokenKind.DL_ELEMENT, 'value' : 'dl'}, |
| 225 const {'type': TokenKind.DT_ELEMENT, 'value' : 'dt'}, |
| 226 const {'type': TokenKind.EM_ELEMENT, 'value' : 'em'}, |
| 227 const {'type': TokenKind.FIELDSET_ELEMENT, 'value' : 'fieldset'}, |
| 228 const {'type': TokenKind.FONT_ELEMENT, 'value' : 'font'}, |
| 229 const {'type': TokenKind.FORM_ELEMENT, 'value' : 'form'}, |
| 230 const {'type': TokenKind.FRAME_ELEMENT, 'value' : 'frame'}, |
| 231 const {'type': TokenKind.FRAMESET_ELEMENT, 'value' : 'frameset'}, |
| 232 const {'type': TokenKind.H1_ELEMENT, 'value' : 'h1'}, |
| 233 const {'type': TokenKind.H2_ELEMENT, 'value' : 'h2'}, |
| 234 const {'type': TokenKind.H3_ELEMENT, 'value' : 'h3'}, |
| 235 const {'type': TokenKind.H4_ELEMENT, 'value' : 'h4'}, |
| 236 const {'type': TokenKind.H5_ELEMENT, 'value' : 'h5'}, |
| 237 const {'type': TokenKind.H6_ELEMENT, 'value' : 'h6'}, |
| 238 const {'type': TokenKind.HEAD_ELEMENT, 'value' : 'head'}, |
| 239 const {'type': TokenKind.HR_ELEMENT, 'value' : 'hr'}, |
| 240 const {'type': TokenKind.HTML_ELEMENT, 'value' : 'html'}, |
| 241 const {'type': TokenKind.I_ELEMENT, 'value' : 'i'}, |
| 242 const {'type': TokenKind.IFRAME_ELEMENT, 'value' : 'iframe'}, |
| 243 const {'type': TokenKind.IMG_ELEMENT, 'value' : 'img'}, |
| 244 const {'type': TokenKind.INPUT_ELEMENT, 'value' : 'input'}, |
| 245 const {'type': TokenKind.INS_ELEMENT, 'value' : 'ins'}, |
| 246 const {'type': TokenKind.ISINDEX_ELEMENT, 'value' : 'isindex'}, |
| 247 const {'type': TokenKind.KBD_ELEMENT, 'value' : 'kbd'}, |
| 248 const {'type': TokenKind.LABEL_ELEMENT, 'value' : 'label'}, |
| 249 const {'type': TokenKind.LEGEND_ELEMENT, 'value' : 'legend'}, |
| 250 const {'type': TokenKind.LI_ELEMENT, 'value' : 'li'}, |
| 251 const {'type': TokenKind.LINK_ELEMENT, 'value' : 'link'}, |
| 252 const {'type': TokenKind.MAP_ELEMENT, 'value' : 'map'}, |
| 253 const {'type': TokenKind.MENU_ELEMENT, 'value' : 'menu'}, |
| 254 const {'type': TokenKind.META_ELEMENT, 'value' : 'meta'}, |
| 255 const {'type': TokenKind.NOFRAMES_ELEMENT, 'value' : 'noframes'}, |
| 256 const {'type': TokenKind.NOSCRIPT_ELEMENT, 'value' : 'noscript'}, |
| 257 const {'type': TokenKind.OBJECT_ELEMENT, 'value' : 'object'}, |
| 258 const {'type': TokenKind.OL_ELEMENT, 'value' : 'ol'}, |
| 259 const {'type': TokenKind.OPTGROUP_ELEMENT, 'value' : 'optgroup'}, |
| 260 const {'type': TokenKind.OPTION_ELEMENT, 'value' : 'option'}, |
| 261 const {'type': TokenKind.P_ELEMENT, 'value' : 'p'}, |
| 262 const {'type': TokenKind.PARAM_ELEMENT, 'value' : 'param'}, |
| 263 const {'type': TokenKind.PRE_ELEMENT, 'value' : 'pre'}, |
| 264 const {'type': TokenKind.Q_ELEMENT, 'value' : 'q'}, |
| 265 const {'type': TokenKind.S_ELEMENT, 'value' : 's'}, |
| 266 const {'type': TokenKind.SAMP_ELEMENT, 'value' : 'samp'}, |
| 267 const {'type': TokenKind.SCRIPT_ELEMENT, 'value' : 'script'}, |
| 268 const {'type': TokenKind.SELECT_ELEMENT, 'value' : 'select'}, |
| 269 const {'type': TokenKind.SMALL_ELEMENT, 'value' : 'small'}, |
| 270 const {'type': TokenKind.SPAN_ELEMENT, 'value' : 'span'}, |
| 271 const {'type': TokenKind.STRIKE_ELEMENT, 'value' : 'strike'}, |
| 272 const {'type': TokenKind.STRONG_ELEMENT, 'value' : 'strong'}, |
| 273 const {'type': TokenKind.STYLE_ELEMENT, 'value' : 'style'}, |
| 274 const {'type': TokenKind.SUB_ELEMENT, 'value' : 'sub'}, |
| 275 const {'type': TokenKind.SUP_ELEMENT, 'value' : 'sup'}, |
| 276 const {'type': TokenKind.TABLE_ELEMENT, 'value' : 'table'}, |
| 277 const {'type': TokenKind.TBODY_ELEMENT, 'value' : 'tbody'}, |
| 278 const {'type': TokenKind.TD_ELEMENT, 'value' : 'td'}, |
| 279 const {'type': TokenKind.TEXTAREA_ELEMENT, 'value' : 'textarea'}, |
| 280 const {'type': TokenKind.TFOOT_ELEMENT, 'value' : 'tfoot'}, |
| 281 const {'type': TokenKind.TH_ELEMENT, 'value' : 'th'}, |
| 282 const {'type': TokenKind.THEAD_ELEMENT, 'value' : 'thead'}, |
| 283 const {'type': TokenKind.TITLE_ELEMENT, 'value' : 'title'}, |
| 284 const {'type': TokenKind.TR_ELEMENT, 'value' : 'tr'}, |
| 285 const {'type': TokenKind.TT_ELEMENT, 'value' : 'tt'}, |
| 286 const {'type': TokenKind.U_ELEMENT, 'value' : 'u'}, |
| 287 const {'type': TokenKind.UL_ELEMENT, 'value' : 'ul'}, |
| 288 const {'type': TokenKind.VAR_ELEMENT, 'value' : 'var'}, |
| 289 ]; |
| 290 |
| 291 // Some more constants: |
| 292 static final int ASCII_UPPER_A = 65; // ASCII value for uppercase A |
| 293 static final int ASCII_UPPER_Z = 90; // ASCII value for uppercase Z |
| 294 |
| 295 List<int> tokens; |
| 296 |
| 297 /* |
| 298 * Return the token that matches the unit ident found. |
| 299 */ |
| 300 static int matchList(var identList, String tokenField, String text, |
| 301 int offset, int length) { |
| 302 for (final entry in identList) { |
| 303 String ident = entry['value']; |
| 304 if (length == ident.length) { |
| 305 int idx = offset; |
| 306 bool match = true; |
| 307 for (int identIdx = 0; identIdx < ident.length; identIdx++) { |
| 308 int identChar = ident.charCodeAt(identIdx); |
| 309 int char = text.charCodeAt(idx++); |
| 310 // Compare lowercase to lowercase then check if char is uppercase. |
| 311 match = match && (char == identChar || |
| 312 ((char >= ASCII_UPPER_A && char <= ASCII_UPPER_Z) && |
| 313 (char + 32) == identChar)); |
| 314 if (!match) { |
| 315 break; |
| 316 } |
| 317 } |
| 318 |
| 319 if (match) { |
| 320 // Completely matched; return the token for this unit. |
| 321 return entry[tokenField]; |
| 322 } |
| 323 } |
| 324 } |
| 325 |
| 326 return -1; // Not a unit token. |
| 327 } |
| 328 |
| 329 /* Map _ELEMENTS type to the real name. */ |
| 330 static String elementsToName(int kind) { |
| 331 for (final entry in TokenKind._ELEMENTS) { |
| 332 if (kind == entry['type']) { |
| 333 return entry['value']; |
| 334 } |
| 335 } |
| 336 } |
| 337 |
| 338 /* |
| 339 * Return the token that matches the element ident found. |
| 340 */ |
| 341 static int matchElements(String text, int offset, int length) { |
| 342 return matchList(_ELEMENTS, 'type', text, offset, length); |
| 343 } |
| 344 |
| 345 static String tagNameFromTokenId(int tagTokenId) { |
| 346 if (tagTokenId >= TokenKind.START_HTML_ELEMENT && |
| 347 tagTokenId <= TokenKind.END_HTML_ELEMENT) { |
| 348 for (final tag in TokenKind._ELEMENTS) { |
| 349 if (tag['type'] == tagTokenId) { |
| 350 return tag['value']; |
| 351 } |
| 352 } |
| 353 } |
| 354 } |
| 355 |
| 356 static int matchKeywords(String text, int offset, int length) { |
| 357 return matchList(_KEYWORDS, 'type', text, offset, length); |
| 358 } |
| 359 |
| 360 static String kindToString(int kind) { |
| 361 switch(kind) { |
| 362 case TokenKind.UNUSED: return "ERROR"; |
| 363 case TokenKind.END_OF_FILE: return "end of file"; |
| 364 case TokenKind.LPAREN: return "("; |
| 365 case TokenKind.RPAREN: return ")"; |
| 366 case TokenKind.LBRACK: return "["; |
| 367 case TokenKind.RBRACK: return "]"; |
| 368 case TokenKind.LBRACE: return "{"; |
| 369 case TokenKind.RBRACE: return "}"; |
| 370 case TokenKind.DOT: return "."; |
| 371 case TokenKind.SEMICOLON: return ";"; |
| 372 case TokenKind.SPACE: return " "; |
| 373 case TokenKind.TAB: return "\t"; |
| 374 case TokenKind.NEWLINE: return "\n"; |
| 375 case TokenKind.RETURN: return "\r"; |
| 376 case TokenKind.COMMA: return ","; |
| 377 case TokenKind.LESS_THAN: return "<"; |
| 378 case TokenKind.GREATER_THAN: return ">"; |
| 379 case TokenKind.SLASH: return "/"; |
| 380 case TokenKind.DOLLAR: return "\$"; |
| 381 case TokenKind.HASH: return "#"; |
| 382 case TokenKind.MINUS: return '-'; |
| 383 case TokenKind.EQUAL: return '='; |
| 384 case TokenKind.DOUBLE_QUOTE: return '"'; |
| 385 case TokenKind.SINGLE_QUOTE: return "'"; |
| 386 case TokenKind.END_NO_SCOPE_TAG: return '/>'; |
| 387 case TokenKind.START_EXPRESSION: return '\${'; |
| 388 case TokenKind.START_COMMAND: return '\${#'; |
| 389 case TokenKind.END_COMMAND: return '\${/'; |
| 390 case TokenKind.EACH_COMMAND: return '\${#each list}'; |
| 391 case TokenKind.WITH_COMMAND: return '\${with object}'; |
| 392 case TokenKind.IF_COMMAND: return '\${#if (expression)}'; |
| 393 case TokenKind.ELSE_COMMAND: return '\${#end}'; |
| 394 case TokenKind.INTEGER: return 'integer'; |
| 395 case TokenKind.DOUBLE: return 'double'; |
| 396 case TokenKind.WHITESPACE: return 'whitespace'; |
| 397 case TokenKind.COMMENT: return 'comment'; |
| 398 case TokenKind.ERROR: return 'error'; |
| 399 case TokenKind.INCOMPLETE_STRING : return 'incomplete string'; |
| 400 case TokenKind.INCOMPLETE_COMMENT: return 'incomplete comment'; |
| 401 case TokenKind.ATTR_VALUE: return 'attribute value'; |
| 402 case TokenKind.NUMBER: return 'number'; |
| 403 case TokenKind.HEX_NUMBER: return 'hex number'; |
| 404 case TokenKind.HTML_COMMENT: return 'HTML comment <!-- -->'; |
| 405 case TokenKind.IDENTIFIER: return 'identifier'; |
| 406 case TokenKind.STRING: return 'string'; |
| 407 case TokenKind.STRING_PART: return 'string part'; |
| 408 case TokenKind.TEMPLATE_KEYWORD: return 'template'; |
| 409 default: |
| 410 throw "Unknown TOKEN"; |
| 411 } |
| 412 } |
| 413 |
| 414 TokenKind() { |
| 415 tokens = []; |
| 416 |
| 417 // All tokens must be in TokenKind order. |
| 418 tokens.add(-1); // TokenKind.UNUSED |
| 419 tokens.add(0); // TokenKind.END_OF_FILE match base |
| 420 tokens.add(TokenKind.kindToString(TokenKind.LPAREN).charCodeAt(0)); |
| 421 tokens.add(TokenKind.kindToString(TokenKind.RPAREN).charCodeAt(0)); |
| 422 tokens.add(TokenKind.kindToString(TokenKind.LBRACK).charCodeAt(0)); |
| 423 tokens.add(TokenKind.kindToString(TokenKind.RBRACK).charCodeAt(0)); |
| 424 tokens.add(TokenKind.kindToString(TokenKind.LBRACE).charCodeAt(0)); |
| 425 tokens.add(TokenKind.kindToString(TokenKind.RBRACE).charCodeAt(0)); |
| 426 tokens.add(TokenKind.kindToString(TokenKind.DOT).charCodeAt(0)); |
| 427 tokens.add(TokenKind.kindToString(TokenKind.SEMICOLON).charCodeAt(0)); |
| 428 tokens.add(TokenKind.kindToString(TokenKind.SPACE).charCodeAt(0)); |
| 429 tokens.add(TokenKind.kindToString(TokenKind.TAB).charCodeAt(0)); |
| 430 tokens.add(TokenKind.kindToString(TokenKind.NEWLINE).charCodeAt(0)); |
| 431 tokens.add(TokenKind.kindToString(TokenKind.RETURN).charCodeAt(0)); |
| 432 tokens.add(TokenKind.kindToString(TokenKind.COMMA).charCodeAt(0)); |
| 433 tokens.add(TokenKind.kindToString(TokenKind.LESS_THAN).charCodeAt(0)); |
| 434 tokens.add(TokenKind.kindToString(TokenKind.GREATER_THAN).charCodeAt(0)); |
| 435 tokens.add(TokenKind.kindToString(TokenKind.SLASH).charCodeAt(0)); |
| 436 tokens.add(TokenKind.kindToString(TokenKind.DOLLAR).charCodeAt(0)); |
| 437 tokens.add(TokenKind.kindToString(TokenKind.HASH).charCodeAt(0)); |
| 438 tokens.add(TokenKind.kindToString(TokenKind.MINUS).charCodeAt(0)); |
| 439 tokens.add(TokenKind.kindToString(TokenKind.EQUAL).charCodeAt(0)); |
| 440 tokens.add(TokenKind.kindToString(TokenKind.DOUBLE_QUOTE).charCodeAt(0)); |
| 441 tokens.add(TokenKind.kindToString(TokenKind.SINGLE_QUOTE).charCodeAt(0)); |
| 442 |
| 443 assert(tokens.length == TokenKind.END_TOKENS); |
| 444 } |
| 445 |
| 446 static bool isIdentifier(int kind) { |
| 447 return kind == IDENTIFIER; |
| 448 } |
| 449 } |
| 450 |
| 451 class NoElementMatchException implements Exception { |
| 452 String _tagName; |
| 453 NoElementMatchException(this._tagName); |
| 454 |
| 455 String get name() => _tagName; |
| 456 } |
OLD | NEW |