| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 | 3 |
| 4 library engine.scanner; | 4 library engine.scanner; |
| 5 | 5 |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'java_core.dart'; | 7 import 'java_core.dart'; |
| 8 import 'java_engine.dart'; | 8 import 'java_engine.dart'; |
| 9 import 'source.dart'; | 9 import 'source.dart'; |
| 10 import 'error.dart'; | 10 import 'error.dart'; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 ILLEGAL_CHARACTER, | 156 ILLEGAL_CHARACTER, |
| 157 MISSING_DIGIT, | 157 MISSING_DIGIT, |
| 158 MISSING_HEX_DIGIT, | 158 MISSING_HEX_DIGIT, |
| 159 MISSING_QUOTE, | 159 MISSING_QUOTE, |
| 160 UNTERMINATED_MULTI_LINE_COMMENT, | 160 UNTERMINATED_MULTI_LINE_COMMENT, |
| 161 UNTERMINATED_STRING_LITERAL]; | 161 UNTERMINATED_STRING_LITERAL]; |
| 162 | 162 |
| 163 /** | 163 /** |
| 164 * The template used to create the message to be displayed for this error. | 164 * The template used to create the message to be displayed for this error. |
| 165 */ | 165 */ |
| 166 String _message; | 166 final String message; |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * The template used to create the correction to be displayed for this error,
or `null` if | 169 * The template used to create the correction to be displayed for this error,
or `null` if |
| 170 * there is no correction information for this error. | 170 * there is no correction information for this error. |
| 171 */ | 171 */ |
| 172 String correction10; | 172 String correction10; |
| 173 | 173 |
| 174 /** | 174 /** |
| 175 * Initialize a newly created error code to have the given message. | 175 * Initialize a newly created error code to have the given message. |
| 176 * | 176 * |
| 177 * @param message the message template used to create the message to be displa
yed for this error | 177 * @param message the message template used to create the message to be displa
yed for this error |
| 178 */ | 178 */ |
| 179 ScannerErrorCode.con1(String name, int ordinal, String message) : super(name,
ordinal) { | 179 ScannerErrorCode.con1(String name, int ordinal, this.message) : super(name, or
dinal); |
| 180 this._message = message; | |
| 181 } | |
| 182 | 180 |
| 183 /** | 181 /** |
| 184 * Initialize a newly created error code to have the given message and correct
ion. | 182 * Initialize a newly created error code to have the given message and correct
ion. |
| 185 * | 183 * |
| 186 * @param message the template used to create the message to be displayed for
the error | 184 * @param message the template used to create the message to be displayed for
the error |
| 187 * @param correction the template used to create the correction to be displaye
d for the error | 185 * @param correction the template used to create the correction to be displaye
d for the error |
| 188 */ | 186 */ |
| 189 ScannerErrorCode.con2(String name, int ordinal, String message, String correct
ion) : super(name, ordinal) { | 187 ScannerErrorCode.con2(String name, int ordinal, this.message, String correctio
n) : super(name, ordinal) { |
| 190 this._message = message; | |
| 191 this.correction10 = correction; | 188 this.correction10 = correction; |
| 192 } | 189 } |
| 193 | 190 |
| 194 String get correction => correction10; | 191 String get correction => correction10; |
| 195 | 192 |
| 196 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; | 193 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; |
| 197 | 194 |
| 198 String get message => _message; | |
| 199 | |
| 200 ErrorType get type => ErrorType.SYNTACTIC_ERROR; | 195 ErrorType get type => ErrorType.SYNTACTIC_ERROR; |
| 201 } | 196 } |
| 202 | 197 |
| 203 /** | 198 /** |
| 204 * Instances of the class `SubSequenceReader` implement a [CharacterReader] that
reads | 199 * Instances of the class `SubSequenceReader` implement a [CharacterReader] that
reads |
| 205 * characters from a character sequence, but adds a delta when reporting the cur
rent character | 200 * characters from a character sequence, but adds a delta when reporting the cur
rent character |
| 206 * offset so that the character sequence can be a subsequence from a larger sequ
ence. | 201 * offset so that the character sequence can be a subsequence from a larger sequ
ence. |
| 207 */ | 202 */ |
| 208 class SubSequenceReader extends CharSequenceReader { | 203 class SubSequenceReader extends CharSequenceReader { |
| 209 /** | 204 /** |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 LIBRARY, | 412 LIBRARY, |
| 418 OPERATOR, | 413 OPERATOR, |
| 419 PART, | 414 PART, |
| 420 SET, | 415 SET, |
| 421 STATIC, | 416 STATIC, |
| 422 TYPEDEF]; | 417 TYPEDEF]; |
| 423 | 418 |
| 424 /** | 419 /** |
| 425 * The lexeme for the keyword. | 420 * The lexeme for the keyword. |
| 426 */ | 421 */ |
| 427 String syntax; | 422 String _syntax; |
| 428 | 423 |
| 429 /** | 424 /** |
| 430 * A flag indicating whether the keyword is a pseudo-keyword. Pseudo keywords
can be used as | 425 * A flag indicating whether the keyword is a pseudo-keyword. Pseudo keywords
can be used as |
| 431 * identifiers. | 426 * identifiers. |
| 432 */ | 427 */ |
| 433 bool isPseudoKeyword = false; | 428 bool _isPseudoKeyword2 = false; |
| 434 | 429 |
| 435 /** | 430 /** |
| 436 * A table mapping the lexemes of keywords to the corresponding keyword. | 431 * A table mapping the lexemes of keywords to the corresponding keyword. |
| 437 */ | 432 */ |
| 438 static Map<String, Keyword> keywords = createKeywordMap(); | 433 static Map<String, Keyword> keywords = createKeywordMap(); |
| 439 | 434 |
| 440 /** | 435 /** |
| 441 * Create a table mapping the lexemes of keywords to the corresponding keyword
. | 436 * Create a table mapping the lexemes of keywords to the corresponding keyword
. |
| 442 * | 437 * |
| 443 * @return the table that was created | 438 * @return the table that was created |
| 444 */ | 439 */ |
| 445 static Map<String, Keyword> createKeywordMap() { | 440 static Map<String, Keyword> createKeywordMap() { |
| 446 LinkedHashMap<String, Keyword> result = new LinkedHashMap<String, Keyword>()
; | 441 LinkedHashMap<String, Keyword> result = new LinkedHashMap<String, Keyword>()
; |
| 447 for (Keyword keyword in values) { | 442 for (Keyword keyword in values) { |
| 448 result[keyword.syntax] = keyword; | 443 result[keyword._syntax] = keyword; |
| 449 } | 444 } |
| 450 return result; | 445 return result; |
| 451 } | 446 } |
| 452 | 447 |
| 453 /** | 448 /** |
| 454 * Initialize a newly created keyword to have the given syntax. The keyword is
not a | 449 * Initialize a newly created keyword to have the given syntax. The keyword is
not a |
| 455 * pseudo-keyword. | 450 * pseudo-keyword. |
| 456 * | 451 * |
| 457 * @param syntax the lexeme for the keyword | 452 * @param syntax the lexeme for the keyword |
| 458 */ | 453 */ |
| 459 Keyword.con1(String name, int ordinal, String syntax) : this.con2(name, ordina
l, syntax, false); | 454 Keyword.con1(String name, int ordinal, String syntax) : this.con2(name, ordina
l, syntax, false); |
| 460 | 455 |
| 461 /** | 456 /** |
| 462 * Initialize a newly created keyword to have the given syntax. The keyword is
a pseudo-keyword if | 457 * Initialize a newly created keyword to have the given syntax. The keyword is
a pseudo-keyword if |
| 463 * the given flag is `true`. | 458 * the given flag is `true`. |
| 464 * | 459 * |
| 465 * @param syntax the lexeme for the keyword | 460 * @param syntax the lexeme for the keyword |
| 466 * @param isPseudoKeyword `true` if this keyword is a pseudo-keyword | 461 * @param isPseudoKeyword `true` if this keyword is a pseudo-keyword |
| 467 */ | 462 */ |
| 468 Keyword.con2(String name, int ordinal, String syntax, bool isPseudoKeyword) :
super(name, ordinal) { | 463 Keyword.con2(String name, int ordinal, String syntax, bool isPseudoKeyword) :
super(name, ordinal) { |
| 469 this.syntax = syntax; | 464 this._syntax = syntax; |
| 470 this.isPseudoKeyword = isPseudoKeyword; | 465 this._isPseudoKeyword2 = isPseudoKeyword; |
| 471 } | 466 } |
| 467 |
| 468 /** |
| 469 * Return the lexeme for the keyword. |
| 470 * |
| 471 * @return the lexeme for the keyword |
| 472 */ |
| 473 String get syntax => _syntax; |
| 474 |
| 475 /** |
| 476 * Return `true` if this keyword is a pseudo-keyword. Pseudo keywords can be u
sed as |
| 477 * identifiers. |
| 478 * |
| 479 * @return `true` if this keyword is a pseudo-keyword |
| 480 */ |
| 481 bool get isPseudoKeyword => _isPseudoKeyword2; |
| 472 } | 482 } |
| 473 | 483 |
| 474 /** | 484 /** |
| 475 * Instances of the class `CharSequenceReader` implement a [CharacterReader] tha
t reads | 485 * Instances of the class `CharSequenceReader` implement a [CharacterReader] tha
t reads |
| 476 * characters from a character sequence. | 486 * characters from a character sequence. |
| 477 */ | 487 */ |
| 478 class CharSequenceReader implements CharacterReader { | 488 class CharSequenceReader implements CharacterReader { |
| 479 /** | 489 /** |
| 480 * The sequence from which characters will be read. | 490 * The sequence from which characters will be read. |
| 481 */ | 491 */ |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 */ | 561 */ |
| 552 class IncrementalScanner extends Scanner { | 562 class IncrementalScanner extends Scanner { |
| 553 /** | 563 /** |
| 554 * The reader used to access the characters in the source. | 564 * The reader used to access the characters in the source. |
| 555 */ | 565 */ |
| 556 CharacterReader _reader; | 566 CharacterReader _reader; |
| 557 | 567 |
| 558 /** | 568 /** |
| 559 * A map from tokens that were copied to the copies of the tokens. | 569 * A map from tokens that were copied to the copies of the tokens. |
| 560 */ | 570 */ |
| 561 final TokenMap tokenMap = new TokenMap(); | 571 TokenMap _tokenMap = new TokenMap(); |
| 562 | 572 |
| 563 /** | 573 /** |
| 564 * The token in the new token stream immediately to the left of the range of t
okens that were | 574 * The token in the new token stream immediately to the left of the range of t
okens that were |
| 565 * inserted, or the token immediately to the left of the modified region if th
ere were no new | 575 * inserted, or the token immediately to the left of the modified region if th
ere were no new |
| 566 * tokens. | 576 * tokens. |
| 567 */ | 577 */ |
| 568 Token leftToken; | 578 Token _leftToken; |
| 569 | 579 |
| 570 /** | 580 /** |
| 571 * The token in the new token stream immediately to the right of the range of
tokens that were | 581 * The token in the new token stream immediately to the right of the range of
tokens that were |
| 572 * inserted, or the token immediately to the right of the modified region if t
here were no new | 582 * inserted, or the token immediately to the right of the modified region if t
here were no new |
| 573 * tokens. | 583 * tokens. |
| 574 */ | 584 */ |
| 575 Token rightToken; | 585 Token _rightToken; |
| 576 | 586 |
| 577 /** | 587 /** |
| 578 * A flag indicating whether there were any tokens changed as a result of the
modification. | 588 * A flag indicating whether there were any tokens changed as a result of the
modification. |
| 579 */ | 589 */ |
| 580 bool _hasNonWhitespaceChange2 = false; | 590 bool _hasNonWhitespaceChange2 = false; |
| 581 | 591 |
| 582 /** | 592 /** |
| 583 * Initialize a newly created scanner. | 593 * Initialize a newly created scanner. |
| 584 * | 594 * |
| 585 * @param source the source being scanned | 595 * @param source the source being scanned |
| 586 * @param reader the character reader used to read the characters in the sourc
e | 596 * @param reader the character reader used to read the characters in the sourc
e |
| 587 * @param errorListener the error listener that will be informed of any errors
that are found | 597 * @param errorListener the error listener that will be informed of any errors
that are found |
| 588 */ | 598 */ |
| 589 IncrementalScanner(Source source, CharacterReader reader, AnalysisErrorListene
r errorListener) : super(source, reader, errorListener) { | 599 IncrementalScanner(Source source, CharacterReader reader, AnalysisErrorListene
r errorListener) : super(source, reader, errorListener) { |
| 590 this._reader = reader; | 600 this._reader = reader; |
| 591 } | 601 } |
| 592 | 602 |
| 593 /** | 603 /** |
| 604 * Return the token in the new token stream immediately to the left of the ran
ge of tokens that |
| 605 * were inserted, or the token immediately to the left of the modified region
if there were no new |
| 606 * tokens. |
| 607 * |
| 608 * @return the token to the left of the inserted tokens |
| 609 */ |
| 610 Token get leftToken => _leftToken; |
| 611 |
| 612 /** |
| 613 * Return the token in the new token stream immediately to the right of the ra
nge of tokens that |
| 614 * were inserted, or the token immediately to the right of the modified region
if there were no |
| 615 * new tokens. |
| 616 * |
| 617 * @return the token to the right of the inserted tokens |
| 618 */ |
| 619 Token get rightToken => _rightToken; |
| 620 |
| 621 /** |
| 622 * Return a map from tokens that were copied to the copies of the tokens. |
| 623 * |
| 624 * @return a map from tokens that were copied to the copies of the tokens |
| 625 */ |
| 626 TokenMap get tokenMap => _tokenMap; |
| 627 |
| 628 /** |
| 594 * Return `true` if there were any tokens either added or removed (or both) as
a result of | 629 * Return `true` if there were any tokens either added or removed (or both) as
a result of |
| 595 * the modification. | 630 * the modification. |
| 596 * | 631 * |
| 597 * @return `true` if there were any tokens changed as a result of the modifica
tion | 632 * @return `true` if there were any tokens changed as a result of the modifica
tion |
| 598 */ | 633 */ |
| 599 bool hasNonWhitespaceChange() => _hasNonWhitespaceChange2; | 634 bool hasNonWhitespaceChange() => _hasNonWhitespaceChange2; |
| 600 | 635 |
| 601 /** | 636 /** |
| 602 * Given the stream of tokens scanned from the original source, the modified s
ource (the result of | 637 * Given the stream of tokens scanned from the original source, the modified s
ource (the result of |
| 603 * replacing one contiguous range of characters with another string of charact
ers), and a | 638 * replacing one contiguous range of characters with another string of charact
ers), and a |
| 604 * specification of the modification that was made, return a stream of tokens
scanned from the | 639 * specification of the modification that was made, return a stream of tokens
scanned from the |
| 605 * modified source. The original stream of tokens will not be modified. | 640 * modified source. The original stream of tokens will not be modified. |
| 606 * | 641 * |
| 607 * @param originalStream the stream of tokens scanned from the original source | 642 * @param originalStream the stream of tokens scanned from the original source |
| 608 * @param index the index of the first character in both the original and modi
fied source that was | 643 * @param index the index of the first character in both the original and modi
fied source that was |
| 609 * affected by the modification | 644 * affected by the modification |
| 610 * @param removedLength the number of characters removed from the original sou
rce | 645 * @param removedLength the number of characters removed from the original sou
rce |
| 611 * @param insertedLength the number of characters added to the modified source | 646 * @param insertedLength the number of characters added to the modified source |
| 612 */ | 647 */ |
| 613 Token rescan(Token originalStream, int index, int removedLength, int insertedL
ength) { | 648 Token rescan(Token originalStream, int index, int removedLength, int insertedL
ength) { |
| 614 while (originalStream.type != TokenType.EOF && originalStream.end < index) { | 649 while (originalStream.type != TokenType.EOF && originalStream.end < index) { |
| 615 originalStream = copyAndAdvance(originalStream, 0); | 650 originalStream = copyAndAdvance(originalStream, 0); |
| 616 } | 651 } |
| 617 Token oldFirst = originalStream; | 652 Token oldFirst = originalStream; |
| 618 Token oldLeftToken = originalStream.previous; | 653 Token oldLeftToken = originalStream.previous; |
| 619 leftToken = tail; | 654 _leftToken = tail; |
| 620 int removedEnd = index + (removedLength == 0 ? 0 : removedLength - 1); | 655 int removedEnd = index + (removedLength == 0 ? 0 : removedLength - 1); |
| 621 while (originalStream.type != TokenType.EOF && originalStream.offset <= remo
vedEnd) { | 656 while (originalStream.type != TokenType.EOF && originalStream.offset <= remo
vedEnd) { |
| 622 originalStream = originalStream.next; | 657 originalStream = originalStream.next; |
| 623 } | 658 } |
| 624 Token oldLast; | 659 Token oldLast; |
| 625 Token oldRightToken; | 660 Token oldRightToken; |
| 626 if (originalStream.type != TokenType.EOF && removedEnd + 1 == originalStream
.offset) { | 661 if (originalStream.type != TokenType.EOF && removedEnd + 1 == originalStream
.offset) { |
| 627 oldLast = originalStream; | 662 oldLast = originalStream; |
| 628 originalStream = originalStream.next; | 663 originalStream = originalStream.next; |
| 629 oldRightToken = originalStream; | 664 oldRightToken = originalStream; |
| 630 } else { | 665 } else { |
| 631 oldLast = originalStream.previous; | 666 oldLast = originalStream.previous; |
| 632 oldRightToken = originalStream; | 667 oldRightToken = originalStream; |
| 633 } | 668 } |
| 634 int delta = insertedLength - removedLength; | 669 int delta = insertedLength - removedLength; |
| 635 int scanStart = Math.min(oldFirst.offset, index); | 670 int scanStart = Math.min(oldFirst.offset, index); |
| 636 int oldEnd = oldLast.end + delta - 1; | 671 int oldEnd = oldLast.end + delta - 1; |
| 637 int newEnd = index + insertedLength - 1; | 672 int newEnd = index + insertedLength - 1; |
| 638 int scanEnd = Math.max(newEnd, oldEnd); | 673 int scanEnd = Math.max(newEnd, oldEnd); |
| 639 _reader.offset = scanStart - 1; | 674 _reader.offset = scanStart - 1; |
| 640 int next = _reader.advance(); | 675 int next = _reader.advance(); |
| 641 while (next != -1 && _reader.offset <= scanEnd) { | 676 while (next != -1 && _reader.offset <= scanEnd) { |
| 642 next = bigSwitch(next); | 677 next = bigSwitch(next); |
| 643 } | 678 } |
| 644 if (identical(originalStream.type, TokenType.EOF)) { | 679 if (identical(originalStream.type, TokenType.EOF)) { |
| 645 copyAndAdvance(originalStream, delta); | 680 copyAndAdvance(originalStream, delta); |
| 646 rightToken = tail; | 681 _rightToken = tail; |
| 647 rightToken.setNextWithoutSettingPrevious(rightToken); | 682 _rightToken.setNextWithoutSettingPrevious(_rightToken); |
| 648 } else { | 683 } else { |
| 649 originalStream = copyAndAdvance(originalStream, delta); | 684 originalStream = copyAndAdvance(originalStream, delta); |
| 650 rightToken = tail; | 685 _rightToken = tail; |
| 651 while (originalStream.type != TokenType.EOF) { | 686 while (originalStream.type != TokenType.EOF) { |
| 652 originalStream = copyAndAdvance(originalStream, delta); | 687 originalStream = copyAndAdvance(originalStream, delta); |
| 653 } | 688 } |
| 654 Token eof = copyAndAdvance(originalStream, delta); | 689 Token eof = copyAndAdvance(originalStream, delta); |
| 655 eof.setNextWithoutSettingPrevious(eof); | 690 eof.setNextWithoutSettingPrevious(eof); |
| 656 } | 691 } |
| 657 Token newFirst = leftToken.next; | 692 Token newFirst = _leftToken.next; |
| 658 while (newFirst != rightToken && oldFirst != oldRightToken && newFirst.type
!= TokenType.EOF && equals3(oldFirst, newFirst)) { | 693 while (newFirst != _rightToken && oldFirst != oldRightToken && newFirst.type
!= TokenType.EOF && equals3(oldFirst, newFirst)) { |
| 659 tokenMap.put(oldFirst, newFirst); | 694 _tokenMap.put(oldFirst, newFirst); |
| 660 oldLeftToken = oldFirst; | 695 oldLeftToken = oldFirst; |
| 661 oldFirst = oldFirst.next; | 696 oldFirst = oldFirst.next; |
| 662 leftToken = newFirst; | 697 _leftToken = newFirst; |
| 663 newFirst = newFirst.next; | 698 newFirst = newFirst.next; |
| 664 } | 699 } |
| 665 Token newLast = rightToken.previous; | 700 Token newLast = _rightToken.previous; |
| 666 while (newLast != leftToken && oldLast != oldLeftToken && newLast.type != To
kenType.EOF && equals3(oldLast, newLast)) { | 701 while (newLast != _leftToken && oldLast != oldLeftToken && newLast.type != T
okenType.EOF && equals3(oldLast, newLast)) { |
| 667 tokenMap.put(oldLast, newLast); | 702 _tokenMap.put(oldLast, newLast); |
| 668 oldRightToken = oldLast; | 703 oldRightToken = oldLast; |
| 669 oldLast = oldLast.previous; | 704 oldLast = oldLast.previous; |
| 670 rightToken = newLast; | 705 _rightToken = newLast; |
| 671 newLast = newLast.previous; | 706 newLast = newLast.previous; |
| 672 } | 707 } |
| 673 _hasNonWhitespaceChange2 = leftToken.next != rightToken || oldLeftToken.next
!= oldRightToken; | 708 _hasNonWhitespaceChange2 = _leftToken.next != _rightToken || oldLeftToken.ne
xt != oldRightToken; |
| 674 return firstToken; | 709 return firstToken; |
| 675 } | 710 } |
| 676 | 711 |
| 677 Token copyAndAdvance(Token originalToken, int delta) { | 712 Token copyAndAdvance(Token originalToken, int delta) { |
| 678 Token copiedToken = originalToken.copy(); | 713 Token copiedToken = originalToken.copy(); |
| 679 tokenMap.put(originalToken, copiedToken); | 714 _tokenMap.put(originalToken, copiedToken); |
| 680 copiedToken.applyDelta(delta); | 715 copiedToken.applyDelta(delta); |
| 681 appendToken(copiedToken); | 716 appendToken(copiedToken); |
| 682 Token originalComment = originalToken.precedingComments; | 717 Token originalComment = originalToken.precedingComments; |
| 683 Token copiedComment = originalToken.precedingComments; | 718 Token copiedComment = originalToken.precedingComments; |
| 684 while (originalComment != null) { | 719 while (originalComment != null) { |
| 685 tokenMap.put(originalComment, copiedComment); | 720 _tokenMap.put(originalComment, copiedComment); |
| 686 originalComment = originalComment.next; | 721 originalComment = originalComment.next; |
| 687 copiedComment = copiedComment.next; | 722 copiedComment = copiedComment.next; |
| 688 } | 723 } |
| 689 return originalToken.next; | 724 return originalToken.next; |
| 690 } | 725 } |
| 691 | 726 |
| 692 /** | 727 /** |
| 693 * Return `true` if the two tokens are equal to each other. For the purposes o
f the | 728 * Return `true` if the two tokens are equal to each other. For the purposes o
f the |
| 694 * incremental scanner, two tokens are equal if they have the same type and le
xeme. | 729 * incremental scanner, two tokens are equal if they have the same type and le
xeme. |
| 695 * | 730 * |
| (...skipping 12 matching lines...) Expand all Loading... |
| 708 * should be scanned as a single left-shift operator or as two left angle bracke
ts. This scanner | 743 * should be scanned as a single left-shift operator or as two left angle bracke
ts. This scanner |
| 709 * does not have any context, so it always resolves such conflicts by scanning t
he longest possible | 744 * does not have any context, so it always resolves such conflicts by scanning t
he longest possible |
| 710 * token. | 745 * token. |
| 711 * | 746 * |
| 712 * @coverage dart.engine.parser | 747 * @coverage dart.engine.parser |
| 713 */ | 748 */ |
| 714 class Scanner { | 749 class Scanner { |
| 715 /** | 750 /** |
| 716 * The source being scanned. | 751 * The source being scanned. |
| 717 */ | 752 */ |
| 718 Source source; | 753 final Source source; |
| 719 | 754 |
| 720 /** | 755 /** |
| 721 * The reader used to access the characters in the source. | 756 * The reader used to access the characters in the source. |
| 722 */ | 757 */ |
| 723 CharacterReader _reader; | 758 CharacterReader _reader; |
| 724 | 759 |
| 725 /** | 760 /** |
| 726 * The error listener that will be informed of any errors that are found durin
g the scan. | 761 * The error listener that will be informed of any errors that are found durin
g the scan. |
| 727 */ | 762 */ |
| 728 AnalysisErrorListener _errorListener; | 763 AnalysisErrorListener _errorListener; |
| 729 | 764 |
| 730 /** | 765 /** |
| 731 * The flag specifying if documentation comments should be parsed. | 766 * The flag specifying if documentation comments should be parsed. |
| 732 */ | 767 */ |
| 733 bool _preserveComments = true; | 768 bool _preserveComments = true; |
| 734 | 769 |
| 735 /** | 770 /** |
| 736 * The token pointing to the head of the linked list of tokens. | 771 * The token pointing to the head of the linked list of tokens. |
| 737 */ | 772 */ |
| 738 Token _tokens; | 773 Token _tokens; |
| 739 | 774 |
| 740 /** | 775 /** |
| 741 * The last token that was scanned. | 776 * The last token that was scanned. |
| 742 */ | 777 */ |
| 743 Token tail; | 778 Token _tail; |
| 744 | 779 |
| 745 /** | 780 /** |
| 746 * The first token in the list of comment tokens found since the last non-comm
ent token. | 781 * The first token in the list of comment tokens found since the last non-comm
ent token. |
| 747 */ | 782 */ |
| 748 Token _firstComment; | 783 Token _firstComment; |
| 749 | 784 |
| 750 /** | 785 /** |
| 751 * The last token in the list of comment tokens found since the last non-comme
nt token. | 786 * The last token in the list of comment tokens found since the last non-comme
nt token. |
| 752 */ | 787 */ |
| 753 Token _lastComment; | 788 Token _lastComment; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 778 */ | 813 */ |
| 779 bool _hasUnmatchedGroups2 = false; | 814 bool _hasUnmatchedGroups2 = false; |
| 780 | 815 |
| 781 /** | 816 /** |
| 782 * Initialize a newly created scanner. | 817 * Initialize a newly created scanner. |
| 783 * | 818 * |
| 784 * @param source the source being scanned | 819 * @param source the source being scanned |
| 785 * @param reader the character reader used to read the characters in the sourc
e | 820 * @param reader the character reader used to read the characters in the sourc
e |
| 786 * @param errorListener the error listener that will be informed of any errors
that are found | 821 * @param errorListener the error listener that will be informed of any errors
that are found |
| 787 */ | 822 */ |
| 788 Scanner(Source source, CharacterReader reader, AnalysisErrorListener errorList
ener) { | 823 Scanner(this.source, CharacterReader reader, AnalysisErrorListener errorListen
er) { |
| 789 this.source = source; | |
| 790 this._reader = reader; | 824 this._reader = reader; |
| 791 this._errorListener = errorListener; | 825 this._errorListener = errorListener; |
| 792 _tokens = new Token(TokenType.EOF, -1); | 826 _tokens = new Token(TokenType.EOF, -1); |
| 793 _tokens.setNext(_tokens); | 827 _tokens.setNext(_tokens); |
| 794 tail = _tokens; | 828 _tail = _tokens; |
| 795 _tokenStart = -1; | 829 _tokenStart = -1; |
| 796 _lineStarts.add(0); | 830 _lineStarts.add(0); |
| 797 } | 831 } |
| 798 | 832 |
| 799 /** | 833 /** |
| 800 * Return an array containing the offsets of the first character of each line
in the source code. | 834 * Return an array containing the offsets of the first character of each line
in the source code. |
| 801 * | 835 * |
| 802 * @return an array containing the offsets of the first character of each line
in the source code | 836 * @return an array containing the offsets of the first character of each line
in the source code |
| 803 */ | 837 */ |
| 804 List<int> get lineStarts => _lineStarts; | 838 List<int> get lineStarts => _lineStarts; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 } | 898 } |
| 865 | 899 |
| 866 /** | 900 /** |
| 867 * Append the given token to the end of the token stream being scanned. This m
ethod is intended to | 901 * Append the given token to the end of the token stream being scanned. This m
ethod is intended to |
| 868 * be used by subclasses that copy existing tokens and should not normally be
used because it will | 902 * be used by subclasses that copy existing tokens and should not normally be
used because it will |
| 869 * fail to correctly associate any comments with the token being passed in. | 903 * fail to correctly associate any comments with the token being passed in. |
| 870 * | 904 * |
| 871 * @param token the token to be appended | 905 * @param token the token to be appended |
| 872 */ | 906 */ |
| 873 void appendToken(Token token) { | 907 void appendToken(Token token) { |
| 874 tail = tail.setNext(token); | 908 _tail = _tail.setNext(token); |
| 875 } | 909 } |
| 876 | 910 |
| 877 int bigSwitch(int next) { | 911 int bigSwitch(int next) { |
| 878 beginToken(); | 912 beginToken(); |
| 879 if (next == 0xD) { | 913 if (next == 0xD) { |
| 880 next = _reader.advance(); | 914 next = _reader.advance(); |
| 881 if (next == 0xA) { | 915 if (next == 0xA) { |
| 882 next = _reader.advance(); | 916 next = _reader.advance(); |
| 883 } | 917 } |
| 884 recordStartOfLine(); | 918 recordStartOfLine(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 } | 1050 } |
| 1017 | 1051 |
| 1018 /** | 1052 /** |
| 1019 * Return the first token in the token stream that was scanned. | 1053 * Return the first token in the token stream that was scanned. |
| 1020 * | 1054 * |
| 1021 * @return the first token in the token stream that was scanned | 1055 * @return the first token in the token stream that was scanned |
| 1022 */ | 1056 */ |
| 1023 Token get firstToken => _tokens.next; | 1057 Token get firstToken => _tokens.next; |
| 1024 | 1058 |
| 1025 /** | 1059 /** |
| 1060 * Return the last token that was scanned. |
| 1061 * |
| 1062 * @return the last token that was scanned |
| 1063 */ |
| 1064 Token get tail => _tail; |
| 1065 |
| 1066 /** |
| 1026 * Record the fact that we are at the beginning of a new line in the source. | 1067 * Record the fact that we are at the beginning of a new line in the source. |
| 1027 */ | 1068 */ |
| 1028 void recordStartOfLine() { | 1069 void recordStartOfLine() { |
| 1029 _lineStarts.add(_reader.offset); | 1070 _lineStarts.add(_reader.offset); |
| 1030 } | 1071 } |
| 1031 | 1072 |
| 1032 void appendBeginToken(TokenType type) { | 1073 void appendBeginToken(TokenType type) { |
| 1033 BeginToken token; | 1074 BeginToken token; |
| 1034 if (_firstComment == null) { | 1075 if (_firstComment == null) { |
| 1035 token = new BeginToken(type, _tokenStart); | 1076 token = new BeginToken(type, _tokenStart); |
| 1036 } else { | 1077 } else { |
| 1037 token = new BeginTokenWithComment(type, _tokenStart, _firstComment); | 1078 token = new BeginTokenWithComment(type, _tokenStart, _firstComment); |
| 1038 _firstComment = null; | 1079 _firstComment = null; |
| 1039 _lastComment = null; | 1080 _lastComment = null; |
| 1040 } | 1081 } |
| 1041 tail = tail.setNext(token); | 1082 _tail = _tail.setNext(token); |
| 1042 _groupingStack.add(token); | 1083 _groupingStack.add(token); |
| 1043 _stackEnd++; | 1084 _stackEnd++; |
| 1044 } | 1085 } |
| 1045 | 1086 |
| 1046 void appendCommentToken(TokenType type, String value) { | 1087 void appendCommentToken(TokenType type, String value) { |
| 1047 if (!_preserveComments) { | 1088 if (!_preserveComments) { |
| 1048 return; | 1089 return; |
| 1049 } | 1090 } |
| 1050 if (_firstComment == null) { | 1091 if (_firstComment == null) { |
| 1051 _firstComment = new StringToken(type, value, _tokenStart); | 1092 _firstComment = new StringToken(type, value, _tokenStart); |
| 1052 _lastComment = _firstComment; | 1093 _lastComment = _firstComment; |
| 1053 } else { | 1094 } else { |
| 1054 _lastComment = _lastComment.setNext(new StringToken(type, value, _tokenSta
rt)); | 1095 _lastComment = _lastComment.setNext(new StringToken(type, value, _tokenSta
rt)); |
| 1055 } | 1096 } |
| 1056 } | 1097 } |
| 1057 | 1098 |
| 1058 void appendEndToken(TokenType type, TokenType beginType) { | 1099 void appendEndToken(TokenType type, TokenType beginType) { |
| 1059 Token token; | 1100 Token token; |
| 1060 if (_firstComment == null) { | 1101 if (_firstComment == null) { |
| 1061 token = new Token(type, _tokenStart); | 1102 token = new Token(type, _tokenStart); |
| 1062 } else { | 1103 } else { |
| 1063 token = new TokenWithComment(type, _tokenStart, _firstComment); | 1104 token = new TokenWithComment(type, _tokenStart, _firstComment); |
| 1064 _firstComment = null; | 1105 _firstComment = null; |
| 1065 _lastComment = null; | 1106 _lastComment = null; |
| 1066 } | 1107 } |
| 1067 tail = tail.setNext(token); | 1108 _tail = _tail.setNext(token); |
| 1068 if (_stackEnd >= 0) { | 1109 if (_stackEnd >= 0) { |
| 1069 BeginToken begin = _groupingStack[_stackEnd]; | 1110 BeginToken begin = _groupingStack[_stackEnd]; |
| 1070 if (identical(begin.type, beginType)) { | 1111 if (identical(begin.type, beginType)) { |
| 1071 begin.endToken = token; | 1112 begin.endToken = token; |
| 1072 _groupingStack.removeAt(_stackEnd--); | 1113 _groupingStack.removeAt(_stackEnd--); |
| 1073 } | 1114 } |
| 1074 } | 1115 } |
| 1075 } | 1116 } |
| 1076 | 1117 |
| 1077 void appendEofToken() { | 1118 void appendEofToken() { |
| 1078 Token eofToken; | 1119 Token eofToken; |
| 1079 if (_firstComment == null) { | 1120 if (_firstComment == null) { |
| 1080 eofToken = new Token(TokenType.EOF, _reader.offset + 1); | 1121 eofToken = new Token(TokenType.EOF, _reader.offset + 1); |
| 1081 } else { | 1122 } else { |
| 1082 eofToken = new TokenWithComment(TokenType.EOF, _reader.offset + 1, _firstC
omment); | 1123 eofToken = new TokenWithComment(TokenType.EOF, _reader.offset + 1, _firstC
omment); |
| 1083 _firstComment = null; | 1124 _firstComment = null; |
| 1084 _lastComment = null; | 1125 _lastComment = null; |
| 1085 } | 1126 } |
| 1086 eofToken.setNext(eofToken); | 1127 eofToken.setNext(eofToken); |
| 1087 tail = tail.setNext(eofToken); | 1128 _tail = _tail.setNext(eofToken); |
| 1088 if (_stackEnd >= 0) { | 1129 if (_stackEnd >= 0) { |
| 1089 _hasUnmatchedGroups2 = true; | 1130 _hasUnmatchedGroups2 = true; |
| 1090 } | 1131 } |
| 1091 } | 1132 } |
| 1092 | 1133 |
| 1093 void appendKeywordToken(Keyword keyword) { | 1134 void appendKeywordToken(Keyword keyword) { |
| 1094 if (_firstComment == null) { | 1135 if (_firstComment == null) { |
| 1095 tail = tail.setNext(new KeywordToken(keyword, _tokenStart)); | 1136 _tail = _tail.setNext(new KeywordToken(keyword, _tokenStart)); |
| 1096 } else { | 1137 } else { |
| 1097 tail = tail.setNext(new KeywordTokenWithComment(keyword, _tokenStart, _fir
stComment)); | 1138 _tail = _tail.setNext(new KeywordTokenWithComment(keyword, _tokenStart, _f
irstComment)); |
| 1098 _firstComment = null; | 1139 _firstComment = null; |
| 1099 _lastComment = null; | 1140 _lastComment = null; |
| 1100 } | 1141 } |
| 1101 } | 1142 } |
| 1102 | 1143 |
| 1103 void appendStringToken(TokenType type, String value) { | 1144 void appendStringToken(TokenType type, String value) { |
| 1104 if (_firstComment == null) { | 1145 if (_firstComment == null) { |
| 1105 tail = tail.setNext(new StringToken(type, value, _tokenStart)); | 1146 _tail = _tail.setNext(new StringToken(type, value, _tokenStart)); |
| 1106 } else { | 1147 } else { |
| 1107 tail = tail.setNext(new StringTokenWithComment(type, value, _tokenStart, _
firstComment)); | 1148 _tail = _tail.setNext(new StringTokenWithComment(type, value, _tokenStart,
_firstComment)); |
| 1108 _firstComment = null; | 1149 _firstComment = null; |
| 1109 _lastComment = null; | 1150 _lastComment = null; |
| 1110 } | 1151 } |
| 1111 } | 1152 } |
| 1112 | 1153 |
| 1113 void appendStringToken2(TokenType type, String value, int offset) { | 1154 void appendStringToken2(TokenType type, String value, int offset) { |
| 1114 if (_firstComment == null) { | 1155 if (_firstComment == null) { |
| 1115 tail = tail.setNext(new StringToken(type, value, _tokenStart + offset)); | 1156 _tail = _tail.setNext(new StringToken(type, value, _tokenStart + offset)); |
| 1116 } else { | 1157 } else { |
| 1117 tail = tail.setNext(new StringTokenWithComment(type, value, _tokenStart +
offset, _firstComment)); | 1158 _tail = _tail.setNext(new StringTokenWithComment(type, value, _tokenStart
+ offset, _firstComment)); |
| 1118 _firstComment = null; | 1159 _firstComment = null; |
| 1119 _lastComment = null; | 1160 _lastComment = null; |
| 1120 } | 1161 } |
| 1121 } | 1162 } |
| 1122 | 1163 |
| 1123 void appendToken2(TokenType type) { | 1164 void appendToken2(TokenType type) { |
| 1124 if (_firstComment == null) { | 1165 if (_firstComment == null) { |
| 1125 tail = tail.setNext(new Token(type, _tokenStart)); | 1166 _tail = _tail.setNext(new Token(type, _tokenStart)); |
| 1126 } else { | 1167 } else { |
| 1127 tail = tail.setNext(new TokenWithComment(type, _tokenStart, _firstComment)
); | 1168 _tail = _tail.setNext(new TokenWithComment(type, _tokenStart, _firstCommen
t)); |
| 1128 _firstComment = null; | 1169 _firstComment = null; |
| 1129 _lastComment = null; | 1170 _lastComment = null; |
| 1130 } | 1171 } |
| 1131 } | 1172 } |
| 1132 | 1173 |
| 1133 void appendToken3(TokenType type, int offset) { | 1174 void appendToken3(TokenType type, int offset) { |
| 1134 if (_firstComment == null) { | 1175 if (_firstComment == null) { |
| 1135 tail = tail.setNext(new Token(type, offset)); | 1176 _tail = _tail.setNext(new Token(type, offset)); |
| 1136 } else { | 1177 } else { |
| 1137 tail = tail.setNext(new TokenWithComment(type, offset, _firstComment)); | 1178 _tail = _tail.setNext(new TokenWithComment(type, offset, _firstComment)); |
| 1138 _firstComment = null; | 1179 _firstComment = null; |
| 1139 _lastComment = null; | 1180 _lastComment = null; |
| 1140 } | 1181 } |
| 1141 } | 1182 } |
| 1142 | 1183 |
| 1143 void beginToken() { | 1184 void beginToken() { |
| 1144 _tokenStart = _reader.offset; | 1185 _tokenStart = _reader.offset; |
| 1145 } | 1186 } |
| 1146 | 1187 |
| 1147 /** | 1188 /** |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1815 /** | 1856 /** |
| 1816 * Instances of the class `Token` represent a token that was scanned from the in
put. Each | 1857 * Instances of the class `Token` represent a token that was scanned from the in
put. Each |
| 1817 * token knows which token follows it, acting as the head of a linked list of to
kens. | 1858 * token knows which token follows it, acting as the head of a linked list of to
kens. |
| 1818 * | 1859 * |
| 1819 * @coverage dart.engine.parser | 1860 * @coverage dart.engine.parser |
| 1820 */ | 1861 */ |
| 1821 class Token { | 1862 class Token { |
| 1822 /** | 1863 /** |
| 1823 * The type of the token. | 1864 * The type of the token. |
| 1824 */ | 1865 */ |
| 1825 TokenType type; | 1866 final TokenType type; |
| 1826 | 1867 |
| 1827 /** | 1868 /** |
| 1828 * The offset from the beginning of the file to the first character in the tok
en. | 1869 * The offset from the beginning of the file to the first character in the tok
en. |
| 1829 */ | 1870 */ |
| 1830 int offset = 0; | 1871 int offset = 0; |
| 1831 | 1872 |
| 1832 /** | 1873 /** |
| 1833 * The previous token in the token stream. | 1874 * The previous token in the token stream. |
| 1834 */ | 1875 */ |
| 1835 Token previous; | 1876 Token previous; |
| 1836 | 1877 |
| 1837 /** | 1878 /** |
| 1838 * The next token in the token stream. | 1879 * The next token in the token stream. |
| 1839 */ | 1880 */ |
| 1840 Token next; | 1881 Token _next; |
| 1841 | 1882 |
| 1842 /** | 1883 /** |
| 1843 * Initialize a newly created token to have the given type and offset. | 1884 * Initialize a newly created token to have the given type and offset. |
| 1844 * | 1885 * |
| 1845 * @param type the type of the token | 1886 * @param type the type of the token |
| 1846 * @param offset the offset from the beginning of the file to the first charac
ter in the token | 1887 * @param offset the offset from the beginning of the file to the first charac
ter in the token |
| 1847 */ | 1888 */ |
| 1848 Token(TokenType type, int offset) { | 1889 Token(this.type, int offset) { |
| 1849 this.type = type; | |
| 1850 this.offset = offset; | 1890 this.offset = offset; |
| 1851 } | 1891 } |
| 1852 | 1892 |
| 1853 /** | 1893 /** |
| 1854 * Return a newly created token that is a copy of this token but that is not a
part of any token | 1894 * Return a newly created token that is a copy of this token but that is not a
part of any token |
| 1855 * stream. | 1895 * stream. |
| 1856 * | 1896 * |
| 1857 * @return a newly created token that is a copy of this token | 1897 * @return a newly created token that is a copy of this token |
| 1858 */ | 1898 */ |
| 1859 Token copy() => new Token(type, offset); | 1899 Token copy() => new Token(type, offset); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1875 int get length => lexeme.length; | 1915 int get length => lexeme.length; |
| 1876 | 1916 |
| 1877 /** | 1917 /** |
| 1878 * Return the lexeme that represents this token. | 1918 * Return the lexeme that represents this token. |
| 1879 * | 1919 * |
| 1880 * @return the lexeme that represents this token | 1920 * @return the lexeme that represents this token |
| 1881 */ | 1921 */ |
| 1882 String get lexeme => type.lexeme; | 1922 String get lexeme => type.lexeme; |
| 1883 | 1923 |
| 1884 /** | 1924 /** |
| 1925 * Return the next token in the token stream. |
| 1926 * |
| 1927 * @return the next token in the token stream |
| 1928 */ |
| 1929 Token get next => _next; |
| 1930 |
| 1931 /** |
| 1885 * Return the first comment in the list of comments that precede this token, o
r `null` if | 1932 * Return the first comment in the list of comments that precede this token, o
r `null` if |
| 1886 * there are no comments preceding this token. Additional comments can be reac
hed by following the | 1933 * there are no comments preceding this token. Additional comments can be reac
hed by following the |
| 1887 * token stream using [getNext] until `null` is returned. | 1934 * token stream using [getNext] until `null` is returned. |
| 1888 * | 1935 * |
| 1889 * @return the first comment in the list of comments that precede this token | 1936 * @return the first comment in the list of comments that precede this token |
| 1890 */ | 1937 */ |
| 1891 Token get precedingComments => null; | 1938 Token get precedingComments => null; |
| 1892 | 1939 |
| 1893 /** | 1940 /** |
| 1894 * Return `true` if this token represents an operator. | 1941 * Return `true` if this token represents an operator. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1913 bool get isUserDefinableOperator => type.isUserDefinableOperator; | 1960 bool get isUserDefinableOperator => type.isUserDefinableOperator; |
| 1914 | 1961 |
| 1915 /** | 1962 /** |
| 1916 * Set the next token in the token stream to the given token. This has the sid
e-effect of setting | 1963 * Set the next token in the token stream to the given token. This has the sid
e-effect of setting |
| 1917 * this token to be the previous token for the given token. | 1964 * this token to be the previous token for the given token. |
| 1918 * | 1965 * |
| 1919 * @param token the next token in the token stream | 1966 * @param token the next token in the token stream |
| 1920 * @return the token that was passed in | 1967 * @return the token that was passed in |
| 1921 */ | 1968 */ |
| 1922 Token setNext(Token token) { | 1969 Token setNext(Token token) { |
| 1923 next = token; | 1970 _next = token; |
| 1924 token.previous = this; | 1971 token.previous = this; |
| 1925 return token; | 1972 return token; |
| 1926 } | 1973 } |
| 1927 | 1974 |
| 1928 /** | 1975 /** |
| 1929 * Set the next token in the token stream to the given token without changing
which token is the | 1976 * Set the next token in the token stream to the given token without changing
which token is the |
| 1930 * previous token for the given token. | 1977 * previous token for the given token. |
| 1931 * | 1978 * |
| 1932 * @param token the next token in the token stream | 1979 * @param token the next token in the token stream |
| 1933 * @return the token that was passed in | 1980 * @return the token that was passed in |
| 1934 */ | 1981 */ |
| 1935 Token setNextWithoutSettingPrevious(Token token) { | 1982 Token setNextWithoutSettingPrevious(Token token) { |
| 1936 next = token; | 1983 _next = token; |
| 1937 return token; | 1984 return token; |
| 1938 } | 1985 } |
| 1939 | 1986 |
| 1940 String toString() => lexeme; | 1987 String toString() => lexeme; |
| 1941 | 1988 |
| 1942 /** | 1989 /** |
| 1943 * Return the value of this token. For keyword tokens, this is the keyword ass
ociated with the | 1990 * Return the value of this token. For keyword tokens, this is the keyword ass
ociated with the |
| 1944 * token, for other tokens it is the lexeme associated with the token. | 1991 * token, for other tokens it is the lexeme associated with the token. |
| 1945 * | 1992 * |
| 1946 * @return the value of this token | 1993 * @return the value of this token |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2065 | 2112 |
| 2066 /** | 2113 /** |
| 2067 * Instances of the class `KeywordToken` represent a keyword in the language. | 2114 * Instances of the class `KeywordToken` represent a keyword in the language. |
| 2068 * | 2115 * |
| 2069 * @coverage dart.engine.parser | 2116 * @coverage dart.engine.parser |
| 2070 */ | 2117 */ |
| 2071 class KeywordToken extends Token { | 2118 class KeywordToken extends Token { |
| 2072 /** | 2119 /** |
| 2073 * The keyword being represented by this token. | 2120 * The keyword being represented by this token. |
| 2074 */ | 2121 */ |
| 2075 Keyword keyword; | 2122 final Keyword keyword; |
| 2076 | 2123 |
| 2077 /** | 2124 /** |
| 2078 * Initialize a newly created token to represent the given keyword. | 2125 * Initialize a newly created token to represent the given keyword. |
| 2079 * | 2126 * |
| 2080 * @param keyword the keyword being represented by this token | 2127 * @param keyword the keyword being represented by this token |
| 2081 * @param offset the offset from the beginning of the file to the first charac
ter in the token | 2128 * @param offset the offset from the beginning of the file to the first charac
ter in the token |
| 2082 */ | 2129 */ |
| 2083 KeywordToken(Keyword keyword, int offset) : super(TokenType.KEYWORD, offset) { | 2130 KeywordToken(this.keyword, int offset) : super(TokenType.KEYWORD, offset); |
| 2084 this.keyword = keyword; | |
| 2085 } | |
| 2086 | 2131 |
| 2087 Token copy() => new KeywordToken(keyword, offset); | 2132 Token copy() => new KeywordToken(keyword, offset); |
| 2088 | 2133 |
| 2089 String get lexeme => keyword.syntax; | 2134 String get lexeme => keyword.syntax; |
| 2090 | 2135 |
| 2091 Keyword value() => keyword; | 2136 Keyword value() => keyword; |
| 2092 } | 2137 } |
| 2093 | 2138 |
| 2094 /** | 2139 /** |
| 2095 * Instances of the class `BeginToken` represent the opening half of a grouping
pair of | 2140 * Instances of the class `BeginToken` represent the opening half of a grouping
pair of |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2217 MULTIPLICATIVE_OPERATOR, | 2262 MULTIPLICATIVE_OPERATOR, |
| 2218 RELATIONAL_OPERATOR, | 2263 RELATIONAL_OPERATOR, |
| 2219 SHIFT_OPERATOR, | 2264 SHIFT_OPERATOR, |
| 2220 UNARY_POSTFIX_OPERATOR, | 2265 UNARY_POSTFIX_OPERATOR, |
| 2221 UNARY_PREFIX_OPERATOR]; | 2266 UNARY_PREFIX_OPERATOR]; |
| 2222 | 2267 |
| 2223 /** | 2268 /** |
| 2224 * The precedence of tokens of this class, or `0` if the such tokens do not re
present an | 2269 * The precedence of tokens of this class, or `0` if the such tokens do not re
present an |
| 2225 * operator. | 2270 * operator. |
| 2226 */ | 2271 */ |
| 2227 int precedence = 0; | 2272 int _precedence = 0; |
| 2228 | 2273 |
| 2229 TokenClass.con1(String name, int ordinal) : this.con2(name, ordinal, 0); | 2274 TokenClass.con1(String name, int ordinal) : this.con2(name, ordinal, 0); |
| 2230 | 2275 |
| 2231 TokenClass.con2(String name, int ordinal, int precedence) : super(name, ordina
l) { | 2276 TokenClass.con2(String name, int ordinal, int precedence) : super(name, ordina
l) { |
| 2232 this.precedence = precedence; | 2277 this._precedence = precedence; |
| 2233 } | 2278 } |
| 2279 |
| 2280 /** |
| 2281 * Return the precedence of tokens of this class, or `0` if the such tokens do
not represent |
| 2282 * an operator. |
| 2283 * |
| 2284 * @return the precedence of tokens of this class |
| 2285 */ |
| 2286 int get precedence => _precedence; |
| 2234 } | 2287 } |
| 2235 | 2288 |
| 2236 /** | 2289 /** |
| 2237 * Instances of the class `KeywordTokenWithComment` implement a keyword token th
at is preceded | 2290 * Instances of the class `KeywordTokenWithComment` implement a keyword token th
at is preceded |
| 2238 * by comments. | 2291 * by comments. |
| 2239 * | 2292 * |
| 2240 * @coverage dart.engine.parser | 2293 * @coverage dart.engine.parser |
| 2241 */ | 2294 */ |
| 2242 class KeywordTokenWithComment extends KeywordToken { | 2295 class KeywordTokenWithComment extends KeywordToken { |
| 2243 /** | 2296 /** |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2489 | 2542 |
| 2490 /** | 2543 /** |
| 2491 * The class of the token. | 2544 * The class of the token. |
| 2492 */ | 2545 */ |
| 2493 TokenClass _tokenClass; | 2546 TokenClass _tokenClass; |
| 2494 | 2547 |
| 2495 /** | 2548 /** |
| 2496 * The lexeme that defines this type of token, or `null` if there is more than
one possible | 2549 * The lexeme that defines this type of token, or `null` if there is more than
one possible |
| 2497 * lexeme for this type of token. | 2550 * lexeme for this type of token. |
| 2498 */ | 2551 */ |
| 2499 String lexeme; | 2552 String _lexeme; |
| 2500 | 2553 |
| 2501 TokenType.con1(String name, int ordinal) : this.con2(name, ordinal, TokenClass
.NO_CLASS, null); | 2554 TokenType.con1(String name, int ordinal) : this.con2(name, ordinal, TokenClass
.NO_CLASS, null); |
| 2502 | 2555 |
| 2503 TokenType.con2(String name, int ordinal, TokenClass tokenClass, String lexeme)
: super(name, ordinal) { | 2556 TokenType.con2(String name, int ordinal, TokenClass tokenClass, String lexeme)
: super(name, ordinal) { |
| 2504 this._tokenClass = tokenClass == null ? TokenClass.NO_CLASS : tokenClass; | 2557 this._tokenClass = tokenClass == null ? TokenClass.NO_CLASS : tokenClass; |
| 2505 this.lexeme = lexeme; | 2558 this._lexeme = lexeme; |
| 2506 } | 2559 } |
| 2507 | 2560 |
| 2508 /** | 2561 /** |
| 2562 * Return the lexeme that defines this type of token, or `null` if there is mo
re than one |
| 2563 * possible lexeme for this type of token. |
| 2564 * |
| 2565 * @return the lexeme that defines this type of token |
| 2566 */ |
| 2567 String get lexeme => _lexeme; |
| 2568 |
| 2569 /** |
| 2509 * Return the precedence of the token, or `0` if the token does not represent
an operator. | 2570 * Return the precedence of the token, or `0` if the token does not represent
an operator. |
| 2510 * | 2571 * |
| 2511 * @return the precedence of the token | 2572 * @return the precedence of the token |
| 2512 */ | 2573 */ |
| 2513 int get precedence => _tokenClass.precedence; | 2574 int get precedence => _tokenClass.precedence; |
| 2514 | 2575 |
| 2515 /** | 2576 /** |
| 2516 * Return `true` if this type of token represents an additive operator. | 2577 * Return `true` if this type of token represents an additive operator. |
| 2517 * | 2578 * |
| 2518 * @return `true` if this type of token represents an additive operator | 2579 * @return `true` if this type of token represents an additive operator |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2545 * | 2606 * |
| 2546 * @return `true` if this type of token represents an equality operator | 2607 * @return `true` if this type of token represents an equality operator |
| 2547 */ | 2608 */ |
| 2548 bool get isEqualityOperator => identical(_tokenClass, TokenClass.EQUALITY_OPER
ATOR); | 2609 bool get isEqualityOperator => identical(_tokenClass, TokenClass.EQUALITY_OPER
ATOR); |
| 2549 | 2610 |
| 2550 /** | 2611 /** |
| 2551 * Return `true` if this type of token represents an increment operator. | 2612 * Return `true` if this type of token represents an increment operator. |
| 2552 * | 2613 * |
| 2553 * @return `true` if this type of token represents an increment operator | 2614 * @return `true` if this type of token represents an increment operator |
| 2554 */ | 2615 */ |
| 2555 bool get isIncrementOperator => identical(lexeme, "++") || identical(lexeme, "
--"); | 2616 bool get isIncrementOperator => identical(_lexeme, "++") || identical(_lexeme,
"--"); |
| 2556 | 2617 |
| 2557 /** | 2618 /** |
| 2558 * Return `true` if this type of token represents a multiplicative operator. | 2619 * Return `true` if this type of token represents a multiplicative operator. |
| 2559 * | 2620 * |
| 2560 * @return `true` if this type of token represents a multiplicative operator | 2621 * @return `true` if this type of token represents a multiplicative operator |
| 2561 */ | 2622 */ |
| 2562 bool get isMultiplicativeOperator => identical(_tokenClass, TokenClass.MULTIPL
ICATIVE_OPERATOR); | 2623 bool get isMultiplicativeOperator => identical(_tokenClass, TokenClass.MULTIPL
ICATIVE_OPERATOR); |
| 2563 | 2624 |
| 2564 /** | 2625 /** |
| 2565 * Return `true` if this token type represents an operator. | 2626 * Return `true` if this token type represents an operator. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2594 * | 2655 * |
| 2595 * @return `true` if this type of token represents a unary prefix operator | 2656 * @return `true` if this type of token represents a unary prefix operator |
| 2596 */ | 2657 */ |
| 2597 bool get isUnaryPrefixOperator => identical(_tokenClass, TokenClass.UNARY_PREF
IX_OPERATOR); | 2658 bool get isUnaryPrefixOperator => identical(_tokenClass, TokenClass.UNARY_PREF
IX_OPERATOR); |
| 2598 | 2659 |
| 2599 /** | 2660 /** |
| 2600 * Return `true` if this token type represents an operator that can be defined
by users. | 2661 * Return `true` if this token type represents an operator that can be defined
by users. |
| 2601 * | 2662 * |
| 2602 * @return `true` if this token type represents an operator that can be define
d by users | 2663 * @return `true` if this token type represents an operator that can be define
d by users |
| 2603 */ | 2664 */ |
| 2604 bool get isUserDefinableOperator => identical(lexeme, "==") || identical(lexem
e, "~") || identical(lexeme, "[]") || identical(lexeme, "[]=") || identical(lexe
me, "*") || identical(lexeme, "/") || identical(lexeme, "%") || identical(lexeme
, "~/") || identical(lexeme, "+") || identical(lexeme, "-") || identical(lexeme,
"<<") || identical(lexeme, ">>") || identical(lexeme, ">=") || identical(lexeme
, ">") || identical(lexeme, "<=") || identical(lexeme, "<") || identical(lexeme,
"&") || identical(lexeme, "^") || identical(lexeme, "|"); | 2665 bool get isUserDefinableOperator => identical(_lexeme, "==") || identical(_lex
eme, "~") || identical(_lexeme, "[]") || identical(_lexeme, "[]=") || identical(
_lexeme, "*") || identical(_lexeme, "/") || identical(_lexeme, "%") || identical
(_lexeme, "~/") || identical(_lexeme, "+") || identical(_lexeme, "-") || identic
al(_lexeme, "<<") || identical(_lexeme, ">>") || identical(_lexeme, ">=") || ide
ntical(_lexeme, ">") || identical(_lexeme, "<=") || identical(_lexeme, "<") || i
dentical(_lexeme, "&") || identical(_lexeme, "^") || identical(_lexeme, "|"); |
| 2605 } | 2666 } |
| 2606 | 2667 |
| 2607 class TokenType_EOF extends TokenType { | 2668 class TokenType_EOF extends TokenType { |
| 2608 TokenType_EOF(String name, int ordinal, TokenClass arg0, String arg1) : super.
con2(name, ordinal, arg0, arg1); | 2669 TokenType_EOF(String name, int ordinal, TokenClass arg0, String arg1) : super.
con2(name, ordinal, arg0, arg1); |
| 2609 | 2670 |
| 2610 String toString() => "-eof-"; | 2671 String toString() => "-eof-"; |
| 2611 } | 2672 } |
| OLD | NEW |