| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /** | 5 /** |
| 6 * Defines the tokens that are produced by the scanner, used by the parser, and | 6 * Defines the tokens that are produced by the scanner, used by the parser, and |
| 7 * referenced from the [AST structure](ast.dart). | 7 * referenced from the [AST structure](ast.dart). |
| 8 */ | 8 */ |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 /** | 38 /** |
| 39 * The token that corresponds to this token. | 39 * The token that corresponds to this token. |
| 40 */ | 40 */ |
| 41 Token endToken; | 41 Token endToken; |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Initialize a newly created token to have the given [type] at the given | 44 * Initialize a newly created token to have the given [type] at the given |
| 45 * [offset]. | 45 * [offset]. |
| 46 */ | 46 */ |
| 47 BeginToken(TokenType type, int offset) : super(type, offset) { | 47 BeginToken(TokenType type, int offset) : super(type, offset) { |
| 48 assert(type == TokenType.OPEN_CURLY_BRACKET || | 48 assert(type == TokenType.LT || |
| 49 type == TokenType.OPEN_CURLY_BRACKET || |
| 49 type == TokenType.OPEN_PAREN || | 50 type == TokenType.OPEN_PAREN || |
| 50 type == TokenType.OPEN_SQUARE_BRACKET || | 51 type == TokenType.OPEN_SQUARE_BRACKET || |
| 51 type == TokenType.STRING_INTERPOLATION_EXPRESSION); | 52 type == TokenType.STRING_INTERPOLATION_EXPRESSION); |
| 52 } | 53 } |
| 53 | 54 |
| 54 @override | 55 @override |
| 55 Token copy() => new BeginToken(type, offset); | 56 Token copy() => new BeginToken(type, offset); |
| 57 |
| 58 /** |
| 59 * The token that corresponds to this token. |
| 60 */ |
| 61 Token get endGroup => endToken; |
| 62 |
| 63 /** |
| 64 * Set the token that corresponds to this token. |
| 65 */ |
| 66 set endGroup(Token token) { |
| 67 endToken = token; |
| 68 } |
| 56 } | 69 } |
| 57 | 70 |
| 58 /** | 71 /** |
| 59 * A begin token that is preceded by comments. | 72 * A begin token that is preceded by comments. |
| 60 */ | 73 */ |
| 61 class BeginTokenWithComment extends BeginToken implements TokenWithComment { | 74 class BeginTokenWithComment extends BeginToken implements TokenWithComment { |
| 62 /** | 75 /** |
| 63 * The first comment in the list of comments that precede this token. | 76 * The first comment in the list of comments that precede this token. |
| 64 */ | 77 */ |
| 65 @override | 78 @override |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 class SyntheticStringToken extends StringToken { | 718 class SyntheticStringToken extends StringToken { |
| 706 /** | 719 /** |
| 707 * Initialize a newly created token to represent a token of the given [type] | 720 * Initialize a newly created token to represent a token of the given [type] |
| 708 * with the given [value] at the given [offset]. | 721 * with the given [value] at the given [offset]. |
| 709 */ | 722 */ |
| 710 SyntheticStringToken(TokenType type, String value, int offset) | 723 SyntheticStringToken(TokenType type, String value, int offset) |
| 711 : super(type, value, offset); | 724 : super(type, value, offset); |
| 712 | 725 |
| 713 @override | 726 @override |
| 714 bool get isSynthetic => true; | 727 bool get isSynthetic => true; |
| 728 |
| 729 @override |
| 730 Token copy() => new SyntheticStringToken(type, _value, offset); |
| 715 } | 731 } |
| 716 | 732 |
| 717 /** | 733 /** |
| 734 * A synthetic token. |
| 735 */ |
| 736 class SyntheticToken extends SimpleToken { |
| 737 SyntheticToken(TokenType type, int offset) : super(type, offset); |
| 738 |
| 739 @override |
| 740 int get length => 0; |
| 741 |
| 742 @override |
| 743 Token copy() => new SyntheticToken(type, offset); |
| 744 } |
| 745 |
| 746 /** |
| 718 * A token that was scanned from the input. Each token knows which tokens | 747 * A token that was scanned from the input. Each token knows which tokens |
| 719 * precede and follow it, acting as a link in a doubly linked list of tokens. | 748 * precede and follow it, acting as a link in a doubly linked list of tokens. |
| 720 * | 749 * |
| 721 * Clients may not extend, implement or mix-in this class. | 750 * Clients may not extend, implement or mix-in this class. |
| 722 */ | 751 */ |
| 723 abstract class Token implements SyntacticEntity { | 752 abstract class Token implements SyntacticEntity { |
| 724 /** | 753 /** |
| 725 * Initialize a newly created token to have the given [type] and [offset]. | 754 * Initialize a newly created token to have the given [type] and [offset]. |
| 726 */ | 755 */ |
| 727 factory Token(TokenType type, int offset) = SimpleToken; | 756 factory Token(TokenType type, int offset) = SimpleToken; |
| 728 | 757 |
| 729 /** | 758 /** |
| 759 * Initialize a newly created end-of-file token to have the given [offset]. |
| 760 */ |
| 761 factory Token.eof(int offset, [CommentToken precedingComments]) { |
| 762 Token eof = precedingComments == null |
| 763 ? new SimpleToken(TokenType.EOF, offset) |
| 764 : new TokenWithComment(TokenType.EOF, offset, precedingComments); |
| 765 // EOF points to itself so there's always infinite look-ahead. |
| 766 eof.previous = eof; |
| 767 eof.next = eof; |
| 768 return eof; |
| 769 } |
| 770 |
| 771 /** |
| 730 * The number of characters parsed by this token. | 772 * The number of characters parsed by this token. |
| 731 */ | 773 */ |
| 732 int get charCount; | 774 int get charCount; |
| 733 | 775 |
| 734 /** | 776 /** |
| 735 * The character offset of the start of this token within the source text. | 777 * The character offset of the start of this token within the source text. |
| 736 */ | 778 */ |
| 737 int get charOffset; | 779 int get charOffset; |
| 738 | 780 |
| 739 /** | 781 /** |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 | 1680 |
| 1639 void set precedingComments(CommentToken comment) { | 1681 void set precedingComments(CommentToken comment) { |
| 1640 _precedingComment = comment; | 1682 _precedingComment = comment; |
| 1641 _setCommentParent(_precedingComment); | 1683 _setCommentParent(_precedingComment); |
| 1642 } | 1684 } |
| 1643 | 1685 |
| 1644 @override | 1686 @override |
| 1645 Token copy() => | 1687 Token copy() => |
| 1646 new TokenWithComment(type, offset, copyComments(precedingComments)); | 1688 new TokenWithComment(type, offset, copyComments(precedingComments)); |
| 1647 } | 1689 } |
| OLD | NEW |