| 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 final int EOF_TOKEN = 0; | 5 final int EOF_TOKEN = 0; |
| 6 | 6 |
| 7 final int KEYWORD_TOKEN = $k; | 7 final int KEYWORD_TOKEN = $k; |
| 8 final int IDENTIFIER_TOKEN = $a; | 8 final int IDENTIFIER_TOKEN = $a; |
| 9 final int DOUBLE_TOKEN = $d; | 9 final int DOUBLE_TOKEN = $d; |
| 10 final int INT_TOKEN = $i; | 10 final int INT_TOKEN = $i; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 final int PLUS_PLUS_TOKEN = STAR_EQ_TOKEN + 1; | 64 final int PLUS_PLUS_TOKEN = STAR_EQ_TOKEN + 1; |
| 65 final int PLUS_EQ_TOKEN = PLUS_PLUS_TOKEN + 1; | 65 final int PLUS_EQ_TOKEN = PLUS_PLUS_TOKEN + 1; |
| 66 final int MINUS_MINUS_TOKEN = PLUS_EQ_TOKEN + 1; | 66 final int MINUS_MINUS_TOKEN = PLUS_EQ_TOKEN + 1; |
| 67 final int MINUS_EQ_TOKEN = MINUS_MINUS_TOKEN + 1; | 67 final int MINUS_EQ_TOKEN = MINUS_MINUS_TOKEN + 1; |
| 68 final int TILDE_SLASH_EQ_TOKEN = MINUS_EQ_TOKEN + 1; | 68 final int TILDE_SLASH_EQ_TOKEN = MINUS_EQ_TOKEN + 1; |
| 69 final int TILDE_SLASH_TOKEN = TILDE_SLASH_EQ_TOKEN + 1; | 69 final int TILDE_SLASH_TOKEN = TILDE_SLASH_EQ_TOKEN + 1; |
| 70 final int PERCENT_EQ_TOKEN = TILDE_SLASH_TOKEN + 1; | 70 final int PERCENT_EQ_TOKEN = TILDE_SLASH_TOKEN + 1; |
| 71 final int GT_GT_TOKEN = PERCENT_EQ_TOKEN + 1; | 71 final int GT_GT_TOKEN = PERCENT_EQ_TOKEN + 1; |
| 72 final int CARET_EQ_TOKEN = GT_GT_TOKEN + 1; | 72 final int CARET_EQ_TOKEN = GT_GT_TOKEN + 1; |
| 73 final int IS_TOKEN = CARET_EQ_TOKEN + 1; | 73 final int IS_TOKEN = CARET_EQ_TOKEN + 1; |
| 74 final int COMMENT_TOKEN = IS_TOKEN + 1; |
| 75 final int GT_GT_GT_TOKEN = COMMENT_TOKEN + 1; |
| 76 final int STRING_INTERPOLATION_IDENTIFIER_TOKEN = COMMENT_TOKEN + 1; |
| 74 | 77 |
| 75 // TODO(ahe): Get rid of this. | 78 // TODO(ahe): Get rid of this. |
| 76 final int UNKNOWN_TOKEN = 1024; | 79 final int UNKNOWN_TOKEN = 1024; |
| 77 | 80 |
| 78 /** | 81 /** |
| 79 * A token that doubles as a linked list. | 82 * A token that doubles as a linked list. |
| 80 */ | 83 */ |
| 81 class Token { | 84 class Token { |
| 85 /** |
| 86 * The precedence info for this token. [info] determines the kind and the |
| 87 * precedence level of this token. |
| 88 */ |
| 82 final PrecedenceInfo info; | 89 final PrecedenceInfo info; |
| 90 |
| 91 /** |
| 92 * The character offset of the start of this token within the source text. |
| 93 */ |
| 83 final int charOffset; | 94 final int charOffset; |
| 95 |
| 96 /** |
| 97 * The next token in the token stream. |
| 98 */ |
| 84 Token next; | 99 Token next; |
| 85 | 100 |
| 86 Token(PrecedenceInfo this.info, int this.charOffset); | 101 Token(PrecedenceInfo this.info, int this.charOffset); |
| 87 | 102 |
| 88 get value() => info.value; | 103 get value() => info.value; |
| 104 |
| 105 /** |
| 106 * Returns the string value for keywords and symbols. For instance 'class' for |
| 107 * the [CLASS] keyword token and '*' for a [Token] based on [STAR_INFO]. For |
| 108 * other tokens, such identifiers, strings, numbers, etc, [stringValue] |
| 109 * returns [:null:]. |
| 110 * |
| 111 * [stringValue] should only be used for testing keywords and symbols. |
| 112 */ |
| 89 String get stringValue() => info.value.stringValue; | 113 String get stringValue() => info.value.stringValue; |
| 114 |
| 115 /** |
| 116 * The kind enum of this token as determined by its [info]. |
| 117 */ |
| 90 int get kind() => info.kind; | 118 int get kind() => info.kind; |
| 119 |
| 120 /** |
| 121 * The precedence level for this token. |
| 122 */ |
| 91 int get precedence() => info.precedence; | 123 int get precedence() => info.precedence; |
| 92 | 124 |
| 125 /** |
| 126 * Returns a textual representation of this token to be used for debugging |
| 127 * purposes. The resulting string might contain information about the |
| 128 * structure of the token, for example 'StringToken(foo)' for the identifier |
| 129 * token 'foo'. Use [slowToString] for the text actually parsed by the token. |
| 130 */ |
| 93 String toString() => info.value.toString(); | 131 String toString() => info.value.toString(); |
| 94 | 132 |
| 133 /** |
| 134 * The text parsed by this token. |
| 135 */ |
| 95 String slowToString() => toString(); | 136 String slowToString() => toString(); |
| 137 |
| 138 /** |
| 139 * The number of characters parsed by this token. |
| 140 */ |
| 141 int get slowCharLength() => slowToString().length; |
| 96 } | 142 } |
| 97 | 143 |
| 98 /** | 144 /** |
| 99 * A keyword token. | 145 * A keyword token. |
| 100 */ | 146 */ |
| 101 class KeywordToken extends Token { | 147 class KeywordToken extends Token { |
| 102 final Keyword value; | 148 final Keyword value; |
| 103 String get stringValue() => value.syntax; | 149 String get stringValue() => value.syntax; |
| 104 | 150 |
| 105 KeywordToken(Keyword value, int charOffset) | 151 KeywordToken(Keyword value, int charOffset) |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 const PrecedenceInfo(const SourceString('>'), 10, GT_TOKEN); | 406 const PrecedenceInfo(const SourceString('>'), 10, GT_TOKEN); |
| 361 final PrecedenceInfo IS_INFO = | 407 final PrecedenceInfo IS_INFO = |
| 362 const PrecedenceInfo(const SourceString('is'), 10, IS_TOKEN); | 408 const PrecedenceInfo(const SourceString('is'), 10, IS_TOKEN); |
| 363 final PrecedenceInfo LT_EQ_INFO = | 409 final PrecedenceInfo LT_EQ_INFO = |
| 364 const PrecedenceInfo(const SourceString('<='), 10, LT_EQ_TOKEN); | 410 const PrecedenceInfo(const SourceString('<='), 10, LT_EQ_TOKEN); |
| 365 final PrecedenceInfo LT_INFO = | 411 final PrecedenceInfo LT_INFO = |
| 366 const PrecedenceInfo(const SourceString('<'), 10, LT_TOKEN); | 412 const PrecedenceInfo(const SourceString('<'), 10, LT_TOKEN); |
| 367 | 413 |
| 368 // Shift operators. | 414 // Shift operators. |
| 369 final PrecedenceInfo GT_GT_GT_INFO = | 415 final PrecedenceInfo GT_GT_GT_INFO = |
| 370 const PrecedenceInfo(const SourceString('>>>'), 11, GT_GT_TOKEN); | 416 const PrecedenceInfo(const SourceString('>>>'), 11, GT_GT_GT_TOKEN); |
| 371 final PrecedenceInfo GT_GT_INFO = | 417 final PrecedenceInfo GT_GT_INFO = |
| 372 const PrecedenceInfo(const SourceString('>>'), 11, GT_GT_TOKEN); | 418 const PrecedenceInfo(const SourceString('>>'), 11, GT_GT_TOKEN); |
| 373 final PrecedenceInfo LT_LT_INFO = | 419 final PrecedenceInfo LT_LT_INFO = |
| 374 const PrecedenceInfo(const SourceString('<<'), 11, LT_LT_TOKEN); | 420 const PrecedenceInfo(const SourceString('<<'), 11, LT_LT_TOKEN); |
| 375 | 421 |
| 376 // Additive operators. | 422 // Additive operators. |
| 377 final PrecedenceInfo MINUS_INFO = | 423 final PrecedenceInfo MINUS_INFO = |
| 378 const PrecedenceInfo(const SourceString('-'), 12, MINUS_TOKEN); | 424 const PrecedenceInfo(const SourceString('-'), 12, MINUS_TOKEN); |
| 379 final PrecedenceInfo PLUS_INFO = | 425 final PrecedenceInfo PLUS_INFO = |
| 380 const PrecedenceInfo(const SourceString('+'), 12, PLUS_TOKEN); | 426 const PrecedenceInfo(const SourceString('+'), 12, PLUS_TOKEN); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 final PrecedenceInfo CLOSE_SQUARE_BRACKET_INFO = | 475 final PrecedenceInfo CLOSE_SQUARE_BRACKET_INFO = |
| 430 const PrecedenceInfo(const SourceString(']'), 0, CLOSE_SQUARE_BRACKET_TOKEN); | 476 const PrecedenceInfo(const SourceString(']'), 0, CLOSE_SQUARE_BRACKET_TOKEN); |
| 431 | 477 |
| 432 final PrecedenceInfo DOUBLE_INFO = | 478 final PrecedenceInfo DOUBLE_INFO = |
| 433 const PrecedenceInfo(const SourceString('double'), 0, DOUBLE_TOKEN); | 479 const PrecedenceInfo(const SourceString('double'), 0, DOUBLE_TOKEN); |
| 434 | 480 |
| 435 final PrecedenceInfo STRING_INTERPOLATION_INFO = | 481 final PrecedenceInfo STRING_INTERPOLATION_INFO = |
| 436 const PrecedenceInfo(const SourceString('\${'), 0, | 482 const PrecedenceInfo(const SourceString('\${'), 0, |
| 437 STRING_INTERPOLATION_TOKEN); | 483 STRING_INTERPOLATION_TOKEN); |
| 438 | 484 |
| 485 final PrecedenceInfo STRING_INTERPOLATION_IDENTIFIER_INFO = |
| 486 const PrecedenceInfo(const SourceString('\$'), 0, |
| 487 STRING_INTERPOLATION_IDENTIFIER_TOKEN); |
| 488 |
| 439 final PrecedenceInfo HEXADECIMAL_INFO = | 489 final PrecedenceInfo HEXADECIMAL_INFO = |
| 440 const PrecedenceInfo(const SourceString('hexadecimal'), 0, HEXADECIMAL_TOKEN); | 490 const PrecedenceInfo(const SourceString('hexadecimal'), 0, HEXADECIMAL_TOKEN); |
| 441 | 491 |
| 492 final PrecedenceInfo COMMENT_INFO = |
| 493 const PrecedenceInfo(const SourceString('comment'), 0, COMMENT_TOKEN); |
| 494 |
| 442 // For reporting lexical errors. | 495 // For reporting lexical errors. |
| 443 final PrecedenceInfo ERROR_INFO = | 496 final PrecedenceInfo ERROR_INFO = |
| 444 const PrecedenceInfo(const SourceString('?'), 0, UNKNOWN_TOKEN); | 497 const PrecedenceInfo(const SourceString('?'), 0, UNKNOWN_TOKEN); |
| OLD | NEW |