Chromium Code Reviews| 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 * [stringValue] should not be used outside the scanner/parser. | |
|
ahe
2012/06/25 08:12:37
That is not entirely correct. stringValue should o
Johnni Winther
2012/06/25 10:40:00
Done.
| |
| 107 */ | |
| 89 String get stringValue() => info.value.stringValue; | 108 String get stringValue() => info.value.stringValue; |
| 109 | |
| 110 /** | |
| 111 * The kind enum of this token as determined by its [info]. | |
| 112 */ | |
| 90 int get kind() => info.kind; | 113 int get kind() => info.kind; |
| 114 | |
| 115 /** | |
| 116 * The precedence level for this token. | |
| 117 */ | |
| 91 int get precedence() => info.precedence; | 118 int get precedence() => info.precedence; |
| 92 | 119 |
| 93 String toString() => info.value.toString(); | 120 String toString() => info.value.toString(); |
| 94 | 121 |
| 95 String slowToString() => toString(); | 122 String slowToString() => toString(); |
| 123 | |
| 124 /** | |
| 125 * The text parsed by this token. | |
| 126 */ | |
| 127 String get text() => slowToString(); | |
|
ahe
2012/06/25 08:12:37
I'd prefer to use "slowToString()". As it has "slo
Johnni Winther
2012/06/25 10:40:00
Done.
| |
| 128 | |
| 129 /** | |
| 130 * The number of characters parsed by this token. | |
| 131 */ | |
| 132 int get charLength() => text.length; | |
|
ahe
2012/06/25 08:12:37
This is slow.
Johnni Winther
2012/06/25 10:40:00
Done.
| |
| 96 } | 133 } |
| 97 | 134 |
| 98 /** | 135 /** |
| 99 * A keyword token. | 136 * A keyword token. |
| 100 */ | 137 */ |
| 101 class KeywordToken extends Token { | 138 class KeywordToken extends Token { |
| 102 final Keyword value; | 139 final Keyword value; |
| 103 String get stringValue() => value.syntax; | 140 String get stringValue() => value.syntax; |
| 104 | 141 |
| 105 KeywordToken(Keyword value, int charOffset) | 142 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); | 397 const PrecedenceInfo(const SourceString('>'), 10, GT_TOKEN); |
| 361 final PrecedenceInfo IS_INFO = | 398 final PrecedenceInfo IS_INFO = |
| 362 const PrecedenceInfo(const SourceString('is'), 10, IS_TOKEN); | 399 const PrecedenceInfo(const SourceString('is'), 10, IS_TOKEN); |
| 363 final PrecedenceInfo LT_EQ_INFO = | 400 final PrecedenceInfo LT_EQ_INFO = |
| 364 const PrecedenceInfo(const SourceString('<='), 10, LT_EQ_TOKEN); | 401 const PrecedenceInfo(const SourceString('<='), 10, LT_EQ_TOKEN); |
| 365 final PrecedenceInfo LT_INFO = | 402 final PrecedenceInfo LT_INFO = |
| 366 const PrecedenceInfo(const SourceString('<'), 10, LT_TOKEN); | 403 const PrecedenceInfo(const SourceString('<'), 10, LT_TOKEN); |
| 367 | 404 |
| 368 // Shift operators. | 405 // Shift operators. |
| 369 final PrecedenceInfo GT_GT_GT_INFO = | 406 final PrecedenceInfo GT_GT_GT_INFO = |
| 370 const PrecedenceInfo(const SourceString('>>>'), 11, GT_GT_TOKEN); | 407 const PrecedenceInfo(const SourceString('>>>'), 11, GT_GT_GT_TOKEN); |
| 371 final PrecedenceInfo GT_GT_INFO = | 408 final PrecedenceInfo GT_GT_INFO = |
| 372 const PrecedenceInfo(const SourceString('>>'), 11, GT_GT_TOKEN); | 409 const PrecedenceInfo(const SourceString('>>'), 11, GT_GT_TOKEN); |
| 373 final PrecedenceInfo LT_LT_INFO = | 410 final PrecedenceInfo LT_LT_INFO = |
| 374 const PrecedenceInfo(const SourceString('<<'), 11, LT_LT_TOKEN); | 411 const PrecedenceInfo(const SourceString('<<'), 11, LT_LT_TOKEN); |
| 375 | 412 |
| 376 // Additive operators. | 413 // Additive operators. |
| 377 final PrecedenceInfo MINUS_INFO = | 414 final PrecedenceInfo MINUS_INFO = |
| 378 const PrecedenceInfo(const SourceString('-'), 12, MINUS_TOKEN); | 415 const PrecedenceInfo(const SourceString('-'), 12, MINUS_TOKEN); |
| 379 final PrecedenceInfo PLUS_INFO = | 416 final PrecedenceInfo PLUS_INFO = |
| 380 const PrecedenceInfo(const SourceString('+'), 12, PLUS_TOKEN); | 417 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 = | 466 final PrecedenceInfo CLOSE_SQUARE_BRACKET_INFO = |
| 430 const PrecedenceInfo(const SourceString(']'), 0, CLOSE_SQUARE_BRACKET_TOKEN); | 467 const PrecedenceInfo(const SourceString(']'), 0, CLOSE_SQUARE_BRACKET_TOKEN); |
| 431 | 468 |
| 432 final PrecedenceInfo DOUBLE_INFO = | 469 final PrecedenceInfo DOUBLE_INFO = |
| 433 const PrecedenceInfo(const SourceString('double'), 0, DOUBLE_TOKEN); | 470 const PrecedenceInfo(const SourceString('double'), 0, DOUBLE_TOKEN); |
| 434 | 471 |
| 435 final PrecedenceInfo STRING_INTERPOLATION_INFO = | 472 final PrecedenceInfo STRING_INTERPOLATION_INFO = |
| 436 const PrecedenceInfo(const SourceString('\${'), 0, | 473 const PrecedenceInfo(const SourceString('\${'), 0, |
| 437 STRING_INTERPOLATION_TOKEN); | 474 STRING_INTERPOLATION_TOKEN); |
| 438 | 475 |
| 476 final PrecedenceInfo STRING_INTERPOLATION_IDENTIFIER_INFO = | |
| 477 const PrecedenceInfo(const SourceString('\$'), 0, | |
| 478 STRING_INTERPOLATION_IDENTIFIER_TOKEN); | |
| 479 | |
| 439 final PrecedenceInfo HEXADECIMAL_INFO = | 480 final PrecedenceInfo HEXADECIMAL_INFO = |
| 440 const PrecedenceInfo(const SourceString('hexadecimal'), 0, HEXADECIMAL_TOKEN); | 481 const PrecedenceInfo(const SourceString('hexadecimal'), 0, HEXADECIMAL_TOKEN); |
| 441 | 482 |
| 483 final PrecedenceInfo COMMENT_INFO = | |
| 484 const PrecedenceInfo(const SourceString('comment'), 0, COMMENT_TOKEN); | |
| 485 | |
| 442 // For reporting lexical errors. | 486 // For reporting lexical errors. |
| 443 final PrecedenceInfo ERROR_INFO = | 487 final PrecedenceInfo ERROR_INFO = |
| 444 const PrecedenceInfo(const SourceString('?'), 0, UNKNOWN_TOKEN); | 488 const PrecedenceInfo(const SourceString('?'), 0, UNKNOWN_TOKEN); |
| OLD | NEW |