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

Side by Side Diff: lib/compiler/implementation/scanner/token.dart

Issue 10539021: Scanner can include comments in the token stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Nested comments bug fixed Created 8 years, 6 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
OLDNEW
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
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;
74 76
75 // TODO(ahe): Get rid of this. 77 // TODO(ahe): Get rid of this.
76 final int UNKNOWN_TOKEN = 1024; 78 final int UNKNOWN_TOKEN = 1024;
77 79
78 /** 80 /**
79 * A token that doubles as a linked list. 81 * A token that doubles as a linked list.
80 */ 82 */
81 class Token { 83 class Token {
84 /**
85 * The precedence info for this token. [info] determines the kind and the
86 * precedence level of this token.
87 */
82 final PrecedenceInfo info; 88 final PrecedenceInfo info;
89 /**
90 * The character offset of the start of this token within the source text.
91 */
83 final int charOffset; 92 final int charOffset;
93 /**
94 * The next token in the token stream.
95 */
84 Token next; 96 Token next;
85 97
86 Token(PrecedenceInfo this.info, int this.charOffset); 98 Token(PrecedenceInfo this.info, int this.charOffset);
87 99
88 get value() => info.value; 100 get value() => info.value;
101
102 /**
103 * [stringValue] should not be used outside the scanner/parser.
104 */
89 String get stringValue() => info.value.stringValue; 105 String get stringValue() => info.value.stringValue;
106
107 /**
108 * The kind enum of this token as determined by its [info].
109 */
90 int get kind() => info.kind; 110 int get kind() => info.kind;
111
112 /**
113 * The precedence level for this token.
114 */
91 int get precedence() => info.precedence; 115 int get precedence() => info.precedence;
92 116
93 String toString() => info.value.toString(); 117 String toString() => info.value.toString();
94 118
95 String slowToString() => toString(); 119 String slowToString() => toString();
120
121 /**
122 * The text parsed by this token.
123 */
124 String get text() => slowToString();
125
126 /**
127 * The number of characters parsed by this token.
128 */
129 int get charLength() => text.length;
96 } 130 }
97 131
98 /** 132 /**
99 * A keyword token. 133 * A keyword token.
100 */ 134 */
101 class KeywordToken extends Token { 135 class KeywordToken extends Token {
102 final Keyword value; 136 final Keyword value;
103 String get stringValue() => value.syntax; 137 String get stringValue() => value.syntax;
104 138
105 KeywordToken(Keyword value, int charOffset) 139 KeywordToken(Keyword value, int charOffset)
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 const PrecedenceInfo(const SourceString('>'), 10, GT_TOKEN); 394 const PrecedenceInfo(const SourceString('>'), 10, GT_TOKEN);
361 final PrecedenceInfo IS_INFO = 395 final PrecedenceInfo IS_INFO =
362 const PrecedenceInfo(const SourceString('is'), 10, IS_TOKEN); 396 const PrecedenceInfo(const SourceString('is'), 10, IS_TOKEN);
363 final PrecedenceInfo LT_EQ_INFO = 397 final PrecedenceInfo LT_EQ_INFO =
364 const PrecedenceInfo(const SourceString('<='), 10, LT_EQ_TOKEN); 398 const PrecedenceInfo(const SourceString('<='), 10, LT_EQ_TOKEN);
365 final PrecedenceInfo LT_INFO = 399 final PrecedenceInfo LT_INFO =
366 const PrecedenceInfo(const SourceString('<'), 10, LT_TOKEN); 400 const PrecedenceInfo(const SourceString('<'), 10, LT_TOKEN);
367 401
368 // Shift operators. 402 // Shift operators.
369 final PrecedenceInfo GT_GT_GT_INFO = 403 final PrecedenceInfo GT_GT_GT_INFO =
370 const PrecedenceInfo(const SourceString('>>>'), 11, GT_GT_TOKEN); 404 const PrecedenceInfo(const SourceString('>>>'), 11, GT_GT_GT_TOKEN);
371 final PrecedenceInfo GT_GT_INFO = 405 final PrecedenceInfo GT_GT_INFO =
372 const PrecedenceInfo(const SourceString('>>'), 11, GT_GT_TOKEN); 406 const PrecedenceInfo(const SourceString('>>'), 11, GT_GT_TOKEN);
373 final PrecedenceInfo LT_LT_INFO = 407 final PrecedenceInfo LT_LT_INFO =
374 const PrecedenceInfo(const SourceString('<<'), 11, LT_LT_TOKEN); 408 const PrecedenceInfo(const SourceString('<<'), 11, LT_LT_TOKEN);
375 409
376 // Additive operators. 410 // Additive operators.
377 final PrecedenceInfo MINUS_INFO = 411 final PrecedenceInfo MINUS_INFO =
378 const PrecedenceInfo(const SourceString('-'), 12, MINUS_TOKEN); 412 const PrecedenceInfo(const SourceString('-'), 12, MINUS_TOKEN);
379 final PrecedenceInfo PLUS_INFO = 413 final PrecedenceInfo PLUS_INFO =
380 const PrecedenceInfo(const SourceString('+'), 12, PLUS_TOKEN); 414 const PrecedenceInfo(const SourceString('+'), 12, PLUS_TOKEN);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 final PrecedenceInfo DOUBLE_INFO = 466 final PrecedenceInfo DOUBLE_INFO =
433 const PrecedenceInfo(const SourceString('double'), 0, DOUBLE_TOKEN); 467 const PrecedenceInfo(const SourceString('double'), 0, DOUBLE_TOKEN);
434 468
435 final PrecedenceInfo STRING_INTERPOLATION_INFO = 469 final PrecedenceInfo STRING_INTERPOLATION_INFO =
436 const PrecedenceInfo(const SourceString('\${'), 0, 470 const PrecedenceInfo(const SourceString('\${'), 0,
437 STRING_INTERPOLATION_TOKEN); 471 STRING_INTERPOLATION_TOKEN);
438 472
439 final PrecedenceInfo HEXADECIMAL_INFO = 473 final PrecedenceInfo HEXADECIMAL_INFO =
440 const PrecedenceInfo(const SourceString('hexadecimal'), 0, HEXADECIMAL_TOKEN); 474 const PrecedenceInfo(const SourceString('hexadecimal'), 0, HEXADECIMAL_TOKEN);
441 475
476 final PrecedenceInfo COMMENT_INFO =
477 const PrecedenceInfo(const SourceString('comment'), 0, COMMENT_TOKEN);
478
442 // For reporting lexical errors. 479 // For reporting lexical errors.
443 final PrecedenceInfo ERROR_INFO = 480 final PrecedenceInfo ERROR_INFO =
444 const PrecedenceInfo(const SourceString('?'), 0, UNKNOWN_TOKEN); 481 const PrecedenceInfo(const SourceString('?'), 0, UNKNOWN_TOKEN);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698