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

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: 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;
74 75
75 // TODO(ahe): Get rid of this. 76 // TODO(ahe): Get rid of this.
76 final int UNKNOWN_TOKEN = 1024; 77 final int UNKNOWN_TOKEN = 1024;
77 78
78 /** 79 /**
79 * A token that doubles as a linked list. 80 * A token that doubles as a linked list.
80 */ 81 */
81 class Token { 82 class Token {
82 final PrecedenceInfo info; 83 final PrecedenceInfo info;
84 /**
85 * The character offset of the start of this token within the source text.
86 */
83 final int charOffset; 87 final int charOffset;
88 /**
89 * The next token in the token stream.
90 */
84 Token next; 91 Token next;
85 92
86 Token(PrecedenceInfo this.info, int this.charOffset); 93 Token(PrecedenceInfo this.info, int this.charOffset);
87 94
88 get value() => info.value; 95 get value() => info.value;
89 String get stringValue() => info.value.stringValue; 96 String get stringValue() => info.value.stringValue;
90 int get kind() => info.kind; 97 int get kind() => info.kind;
91 int get precedence() => info.precedence; 98 int get precedence() => info.precedence;
92 99
93 String toString() => info.value.toString(); 100 String toString() => info.value.toString();
94 101
95 String slowToString() => toString(); 102 String slowToString() => toString();
103
104 /**
105 * The text parsed by this token.
106 */
107 String get text() => slowToString();
108
109 /**
110 * The number of characters parsed by this token.
111 */
112 int get charLength() => text.length;
96 } 113 }
97 114
98 /** 115 /**
99 * A keyword token. 116 * A keyword token.
100 */ 117 */
101 class KeywordToken extends Token { 118 class KeywordToken extends Token {
102 final Keyword value; 119 final Keyword value;
103 String get stringValue() => value.syntax; 120 String get stringValue() => value.syntax;
104 121
105 KeywordToken(Keyword value, int charOffset) 122 KeywordToken(Keyword value, int charOffset)
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 final PrecedenceInfo DOUBLE_INFO = 449 final PrecedenceInfo DOUBLE_INFO =
433 const PrecedenceInfo(const SourceString('double'), 0, DOUBLE_TOKEN); 450 const PrecedenceInfo(const SourceString('double'), 0, DOUBLE_TOKEN);
434 451
435 final PrecedenceInfo STRING_INTERPOLATION_INFO = 452 final PrecedenceInfo STRING_INTERPOLATION_INFO =
436 const PrecedenceInfo(const SourceString('\${'), 0, 453 const PrecedenceInfo(const SourceString('\${'), 0,
437 STRING_INTERPOLATION_TOKEN); 454 STRING_INTERPOLATION_TOKEN);
438 455
439 final PrecedenceInfo HEXADECIMAL_INFO = 456 final PrecedenceInfo HEXADECIMAL_INFO =
440 const PrecedenceInfo(const SourceString('hexadecimal'), 0, HEXADECIMAL_TOKEN); 457 const PrecedenceInfo(const SourceString('hexadecimal'), 0, HEXADECIMAL_TOKEN);
441 458
459 final PrecedenceInfo COMMENT_INFO =
460 const PrecedenceInfo(const SourceString('comment'), 0, COMMENT_TOKEN);
461
442 // For reporting lexical errors. 462 // For reporting lexical errors.
443 final PrecedenceInfo ERROR_INFO = 463 final PrecedenceInfo ERROR_INFO =
444 const PrecedenceInfo(const SourceString('?'), 0, UNKNOWN_TOKEN); 464 const PrecedenceInfo(const SourceString('?'), 0, UNKNOWN_TOKEN);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698