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

Side by Side Diff: pkg/front_end/lib/src/fasta/scanner/token.dart

Issue 2777153002: move synthetic fasta closers into the token stream (Closed)
Patch Set: rebase Created 3 years, 8 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
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 library fasta.scanner.token; 5 library fasta.scanner.token;
6 6
7 import '../../scanner/token.dart' as analyzer; 7 import '../../scanner/token.dart' as analyzer;
8 8
9 import 'keyword.dart' show Keyword; 9 import 'keyword.dart' show Keyword;
10 10
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 tail = tail.setNext(token.copy()); 208 tail = tail.setNext(token.copy());
209 token = token.next; 209 token = token.next;
210 } 210 }
211 return head; 211 return head;
212 } 212 }
213 213
214 /// Return a copy of the receiver without [preceedingComments]. 214 /// Return a copy of the receiver without [preceedingComments].
215 Token copyWithoutComments(); 215 Token copyWithoutComments();
216 216
217 @override 217 @override
218 bool get isSynthetic => charCount == 0; 218 bool get isSynthetic => false;
219 219
220 @override 220 @override
221 analyzer.Keyword get keyword => null; 221 analyzer.Keyword get keyword => null;
222 222
223 @override 223 @override
224 bool matchesAny(List<analyzer.TokenType> types) { 224 bool matchesAny(List<analyzer.TokenType> types) {
225 for (analyzer.TokenType type in types) { 225 for (analyzer.TokenType type in types) {
226 if (this.type == type) { 226 if (this.type == type) {
227 return true; 227 return true;
228 } 228 }
(...skipping 20 matching lines...) Expand all
249 249
250 /** 250 /**
251 * A [SymbolToken] represents the symbol in its precedence info. 251 * A [SymbolToken] represents the symbol in its precedence info.
252 * Also used for end of file with EOF_INFO. 252 * Also used for end of file with EOF_INFO.
253 */ 253 */
254 class SymbolToken extends Token { 254 class SymbolToken extends Token {
255 final PrecedenceInfo info; 255 final PrecedenceInfo info;
256 256
257 SymbolToken(this.info, int charOffset) : super(charOffset); 257 SymbolToken(this.info, int charOffset) : super(charOffset);
258 258
259 SymbolToken.eof(int charOffset) 259 factory SymbolToken.eof(int charOffset) {
260 : info = EOF_INFO, 260 var eof = new SyntheticSymbolToken(EOF_INFO, charOffset);
261 super(charOffset) {
262 // EOF points to itself so there's always infinite look-ahead. 261 // EOF points to itself so there's always infinite look-ahead.
263 previousToken = this; 262 eof.previousToken = eof;
264 next = this; 263 eof.next = eof;
264 return eof;
265 } 265 }
266 266
267 String get lexeme => info.value; 267 String get lexeme => info.value;
268 268
269 String get stringValue => info.value; 269 String get stringValue => info.value;
270 270
271 bool isIdentifier() => false; 271 bool isIdentifier() => false;
272 272
273 String toString() => "SymbolToken(${info == EOF_INFO ? '-eof-' : lexeme})"; 273 String toString() => "SymbolToken(${info == EOF_INFO ? '-eof-' : lexeme})";
274 274
275 bool get isEof => info == EOF_INFO; 275 bool get isEof => info == EOF_INFO;
276 276
277 @override 277 @override
278 Token copyWithoutComments() => new SymbolToken(info, charOffset); 278 Token copyWithoutComments() => new SymbolToken(info, charOffset);
279 } 279 }
280 280
281 /** 281 /**
282 * A [SyntheticSymbolToken] represents the symbol in its precedence info
283 * which does not exist in the original source.
284 * For example, if the scanner finds '(' missing a ')'
285 * then it will insert an synthetic ')'.
286 */
287 class SyntheticSymbolToken extends SymbolToken {
288 SyntheticSymbolToken(PrecedenceInfo info, int charOffset)
289 : super(info, charOffset);
290
291 @override
292 int get charCount => 0;
293
294 @override
295 bool get isSynthetic => true;
296 }
297
298 /**
282 * A [BeginGroupToken] represents a symbol that may be the beginning of 299 * A [BeginGroupToken] represents a symbol that may be the beginning of
283 * a pair of brackets, i.e., ( { [ < or ${ 300 * a pair of brackets, i.e., ( { [ < or ${
284 * The [endGroup] token points to the matching closing bracked in case 301 * The [endGroup] token points to the matching closing bracked in case
285 * it can be identified during scanning. 302 * it can be identified during scanning.
286 */ 303 */
287 class BeginGroupToken extends SymbolToken implements analyzer.BeginToken { 304 class BeginGroupToken extends SymbolToken implements analyzer.BeginToken {
288 Token endGroup; 305 Token endGroup;
289 306
290 BeginGroupToken(PrecedenceInfo info, int charOffset) 307 BeginGroupToken(PrecedenceInfo info, int charOffset)
291 : super(info, charOffset); 308 : super(info, charOffset);
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 identical(value, "<=") || 637 identical(value, "<=") ||
621 identical(value, "<") || 638 identical(value, "<") ||
622 identical(value, "&") || 639 identical(value, "&") ||
623 identical(value, "^") || 640 identical(value, "^") ||
624 identical(value, "|"); 641 identical(value, "|");
625 } 642 }
626 643
627 bool isTernaryOperator(String value) => identical(value, "[]="); 644 bool isTernaryOperator(String value) => identical(value, "[]=");
628 645
629 bool isMinusOperator(String value) => identical(value, "-"); 646 bool isMinusOperator(String value) => identical(value, "-");
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/array_based_scanner.dart ('k') | pkg/front_end/test/scanner_fasta_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698