| 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 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 '../errors.dart' show internalError; |
| 10 |
| 9 import 'keyword.dart' show Keyword; | 11 import 'keyword.dart' show Keyword; |
| 10 | 12 |
| 11 import 'precedence.dart' | 13 import 'precedence.dart' |
| 12 show | 14 show |
| 13 AS_INFO, | 15 AS_INFO, |
| 14 BAD_INPUT_INFO, | 16 BAD_INPUT_INFO, |
| 15 EOF_INFO, | 17 EOF_INFO, |
| 16 IDENTIFIER_INFO, | 18 IDENTIFIER_INFO, |
| 17 IS_INFO, | 19 IS_INFO, |
| 18 KEYWORD_INFO, | 20 KEYWORD_INFO, |
| 19 MULTI_LINE_COMMENT_INFO, | |
| 20 SINGLE_LINE_COMMENT_INFO, | |
| 21 PrecedenceInfo; | 21 PrecedenceInfo; |
| 22 | 22 |
| 23 import 'token_constants.dart' show IDENTIFIER_TOKEN; | 23 import 'token_constants.dart' show IDENTIFIER_TOKEN; |
| 24 | 24 |
| 25 import 'string_canonicalizer.dart'; | 25 import 'string_canonicalizer.dart'; |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * A token that doubles as a linked list. | 28 * A token that doubles as a linked list. |
| 29 */ | 29 */ |
| 30 abstract class Token implements analyzer.TokenWithComment { | 30 abstract class Token implements analyzer.TokenWithComment { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 | 251 |
| 252 /** | 252 /** |
| 253 * A [SymbolToken] represents the symbol in its precedence info. | 253 * A [SymbolToken] represents the symbol in its precedence info. |
| 254 * Also used for end of file with EOF_INFO. | 254 * Also used for end of file with EOF_INFO. |
| 255 */ | 255 */ |
| 256 class SymbolToken extends Token { | 256 class SymbolToken extends Token { |
| 257 final PrecedenceInfo info; | 257 final PrecedenceInfo info; |
| 258 | 258 |
| 259 SymbolToken(this.info, int charOffset) : super(charOffset); | 259 SymbolToken(this.info, int charOffset) : super(charOffset); |
| 260 | 260 |
| 261 SymbolToken.eof(int charOffset) |
| 262 : info = EOF_INFO, |
| 263 super(charOffset) { |
| 264 // EOF points to itself so there's always infinite look-ahead. |
| 265 previousToken = this; |
| 266 next = this; |
| 267 } |
| 268 |
| 261 String get lexeme => info.value; | 269 String get lexeme => info.value; |
| 262 | 270 |
| 263 String get stringValue => info.value; | 271 String get stringValue => info.value; |
| 264 | 272 |
| 265 bool isIdentifier() => false; | 273 bool isIdentifier() => false; |
| 266 | 274 |
| 267 String toString() => "SymbolToken($lexeme)"; | 275 String toString() => "SymbolToken(${info == EOF_INFO ? '-eof-' : lexeme})"; |
| 268 | 276 |
| 269 bool get isEof => info == EOF_INFO; | 277 bool get isEof => info == EOF_INFO; |
| 270 | 278 |
| 271 @override | 279 @override |
| 272 Token copyWithoutComments() => new SymbolToken(info, charOffset); | 280 Token copyWithoutComments() => new SymbolToken(info, charOffset); |
| 273 } | 281 } |
| 274 | 282 |
| 275 /** | 283 /** |
| 276 * A [BeginGroupToken] represents a symbol that may be the beginning of | 284 * A [BeginGroupToken] represents a symbol that may be the beginning of |
| 277 * a pair of brackets, i.e., ( { [ < or ${ | 285 * a pair of brackets, i.e., ( { [ < or ${ |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 analyzer.TokenWithComment get parent { | 491 analyzer.TokenWithComment get parent { |
| 484 Token token = next; | 492 Token token = next; |
| 485 while (token is CommentToken) { | 493 while (token is CommentToken) { |
| 486 token = token.next; | 494 token = token.next; |
| 487 } | 495 } |
| 488 return token; | 496 return token; |
| 489 } | 497 } |
| 490 | 498 |
| 491 @override | 499 @override |
| 492 void set parent(analyzer.TokenWithComment ignored) { | 500 void set parent(analyzer.TokenWithComment ignored) { |
| 493 throw 'unsupported operation'; | 501 internalError('Internal error: unsupported operation'); |
| 494 } | 502 } |
| 495 | 503 |
| 496 @override | 504 @override |
| 497 void remove() { | 505 void remove() { |
| 498 // TODO: implement remove | 506 // TODO(danrubel): implement remove |
| 499 throw 'not implemented yet'; | 507 internalError('Internal error: not implemented yet'); |
| 500 } | 508 } |
| 501 } | 509 } |
| 502 | 510 |
| 503 class DartDocToken extends CommentToken | 511 class DartDocToken extends CommentToken |
| 504 implements analyzer.DocumentationCommentToken { | 512 implements analyzer.DocumentationCommentToken { |
| 505 /** | 513 /** |
| 506 * The references embedded within the documentation comment. | 514 * The references embedded within the documentation comment. |
| 507 * This list will be empty unless this is a documentation comment that has | 515 * This list will be empty unless this is a documentation comment that has |
| 508 * references embedded within it. | 516 * references embedded within it. |
| 509 */ | 517 */ |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 identical(value, "<=") || | 636 identical(value, "<=") || |
| 629 identical(value, "<") || | 637 identical(value, "<") || |
| 630 identical(value, "&") || | 638 identical(value, "&") || |
| 631 identical(value, "^") || | 639 identical(value, "^") || |
| 632 identical(value, "|"); | 640 identical(value, "|"); |
| 633 } | 641 } |
| 634 | 642 |
| 635 bool isTernaryOperator(String value) => identical(value, "[]="); | 643 bool isTernaryOperator(String value) => identical(value, "[]="); |
| 636 | 644 |
| 637 bool isMinusOperator(String value) => identical(value, "-"); | 645 bool isMinusOperator(String value) => identical(value, "-"); |
| OLD | NEW |