| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.scanner; | 5 library engine.scanner; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'error.dart'; | 9 import 'error.dart'; |
| 10 import 'instrumentation.dart'; | 10 import 'instrumentation.dart'; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 Token copy() => new BeginToken(type, offset); | 36 Token copy() => new BeginToken(type, offset); |
| 37 } | 37 } |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * A `BeginTokenWithComment` is a begin token that is preceded by comments. | 40 * A `BeginTokenWithComment` is a begin token that is preceded by comments. |
| 41 */ | 41 */ |
| 42 class BeginTokenWithComment extends BeginToken { | 42 class BeginTokenWithComment extends BeginToken { |
| 43 /** | 43 /** |
| 44 * The first comment in the list of comments that precede this token. | 44 * The first comment in the list of comments that precede this token. |
| 45 */ | 45 */ |
| 46 CommentToken precedingComments; | 46 CommentToken _precedingComment; |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Initialize a newly created token to have the given [type] at the given | 49 * Initialize a newly created token to have the given [type] at the given |
| 50 * [offset] and to be preceded by the comments reachable from the given | 50 * [offset] and to be preceded by the comments reachable from the given |
| 51 * [comment]. | 51 * [comment]. |
| 52 */ | 52 */ |
| 53 BeginTokenWithComment(TokenType type, int offset, this.precedingComments) | 53 BeginTokenWithComment(TokenType type, int offset, this._precedingComment) |
| 54 : super(type, offset) { | 54 : super(type, offset) { |
| 55 if (precedingComments != null) { | 55 _setCommentParent(_precedingComment); |
| 56 precedingComments.parent = this; | 56 } |
| 57 } | 57 |
| 58 CommentToken get precedingComments => _precedingComment; |
| 59 |
| 60 void set precedingComments(CommentToken comment) { |
| 61 _precedingComment = comment; |
| 62 _setCommentParent(_precedingComment); |
| 58 } | 63 } |
| 59 | 64 |
| 60 @override | 65 @override |
| 61 void applyDelta(int delta) { | 66 void applyDelta(int delta) { |
| 62 super.applyDelta(delta); | 67 super.applyDelta(delta); |
| 63 Token token = precedingComments; | 68 Token token = precedingComments; |
| 64 while (token != null) { | 69 while (token != null) { |
| 65 token.applyDelta(delta); | 70 token.applyDelta(delta); |
| 66 token = token.next; | 71 token = token.next; |
| 67 } | 72 } |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 Keyword value() => keyword; | 593 Keyword value() => keyword; |
| 589 } | 594 } |
| 590 | 595 |
| 591 /** | 596 /** |
| 592 * A `KeywordTokenWithComment` is a keyword token that is preceded by comments. | 597 * A `KeywordTokenWithComment` is a keyword token that is preceded by comments. |
| 593 */ | 598 */ |
| 594 class KeywordTokenWithComment extends KeywordToken { | 599 class KeywordTokenWithComment extends KeywordToken { |
| 595 /** | 600 /** |
| 596 * The first comment in the list of comments that precede this token. | 601 * The first comment in the list of comments that precede this token. |
| 597 */ | 602 */ |
| 598 CommentToken precedingComments; | 603 CommentToken _precedingComment; |
| 599 | 604 |
| 600 /** | 605 /** |
| 601 * Initialize a newly created token to to represent the given [keyword] at the | 606 * Initialize a newly created token to to represent the given [keyword] at the |
| 602 * given [offset] and to be preceded by the comments reachable from the given | 607 * given [offset] and to be preceded by the comments reachable from the given |
| 603 * [comment]. | 608 * [comment]. |
| 604 */ | 609 */ |
| 605 KeywordTokenWithComment(Keyword keyword, int offset, this.precedingComments) | 610 KeywordTokenWithComment(Keyword keyword, int offset, this._precedingComment) |
| 606 : super(keyword, offset) { | 611 : super(keyword, offset) { |
| 607 if (precedingComments != null) { | 612 _setCommentParent(_precedingComment); |
| 608 precedingComments.parent = this; | 613 } |
| 609 } | 614 |
| 615 CommentToken get precedingComments => _precedingComment; |
| 616 |
| 617 void set precedingComments(CommentToken comment) { |
| 618 _precedingComment = comment; |
| 619 _setCommentParent(_precedingComment); |
| 610 } | 620 } |
| 611 | 621 |
| 612 @override | 622 @override |
| 613 void applyDelta(int delta) { | 623 void applyDelta(int delta) { |
| 614 super.applyDelta(delta); | 624 super.applyDelta(delta); |
| 615 Token token = precedingComments; | 625 Token token = precedingComments; |
| 616 while (token != null) { | 626 while (token != null) { |
| 617 token.applyDelta(delta); | 627 token.applyDelta(delta); |
| 618 token = token.next; | 628 token = token.next; |
| 619 } | 629 } |
| (...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1835 String value() => _value; | 1845 String value() => _value; |
| 1836 } | 1846 } |
| 1837 | 1847 |
| 1838 /** | 1848 /** |
| 1839 * A `StringTokenWithComment` is a string token that is preceded by comments. | 1849 * A `StringTokenWithComment` is a string token that is preceded by comments. |
| 1840 */ | 1850 */ |
| 1841 class StringTokenWithComment extends StringToken { | 1851 class StringTokenWithComment extends StringToken { |
| 1842 /** | 1852 /** |
| 1843 * The first comment in the list of comments that precede this token. | 1853 * The first comment in the list of comments that precede this token. |
| 1844 */ | 1854 */ |
| 1845 CommentToken precedingComments; | 1855 CommentToken _precedingComment; |
| 1846 | 1856 |
| 1847 /** | 1857 /** |
| 1848 * Initialize a newly created token to have the given [type] at the given | 1858 * Initialize a newly created token to have the given [type] at the given |
| 1849 * [offset] and to be preceded by the comments reachable from the given | 1859 * [offset] and to be preceded by the comments reachable from the given |
| 1850 * [comment]. | 1860 * [comment]. |
| 1851 */ | 1861 */ |
| 1852 StringTokenWithComment(TokenType type, String value, int offset, | 1862 StringTokenWithComment(TokenType type, String value, int offset, |
| 1853 this.precedingComments) | 1863 this._precedingComment) |
| 1854 : super(type, value, offset) { | 1864 : super(type, value, offset) { |
| 1855 if (precedingComments != null) { | 1865 _setCommentParent(_precedingComment); |
| 1856 precedingComments.parent = this; | 1866 } |
| 1857 } | 1867 |
| 1868 CommentToken get precedingComments => _precedingComment; |
| 1869 |
| 1870 void set precedingComments(CommentToken comment) { |
| 1871 _precedingComment = comment; |
| 1872 _setCommentParent(_precedingComment); |
| 1858 } | 1873 } |
| 1859 | 1874 |
| 1860 @override | 1875 @override |
| 1861 void applyDelta(int delta) { | 1876 void applyDelta(int delta) { |
| 1862 super.applyDelta(delta); | 1877 super.applyDelta(delta); |
| 1863 Token token = precedingComments; | 1878 Token token = precedingComments; |
| 1864 while (token != null) { | 1879 while (token != null) { |
| 1865 token.applyDelta(delta); | 1880 token.applyDelta(delta); |
| 1866 token = token.next; | 1881 token = token.next; |
| 1867 } | 1882 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2076 String toString() => lexeme; | 2091 String toString() => lexeme; |
| 2077 | 2092 |
| 2078 /** | 2093 /** |
| 2079 * Return the value of this token. For keyword tokens, this is the keyword | 2094 * Return the value of this token. For keyword tokens, this is the keyword |
| 2080 * associated with the token, for other tokens it is the lexeme associated | 2095 * associated with the token, for other tokens it is the lexeme associated |
| 2081 * with the token. | 2096 * with the token. |
| 2082 */ | 2097 */ |
| 2083 Object value() => type.lexeme; | 2098 Object value() => type.lexeme; |
| 2084 | 2099 |
| 2085 /** | 2100 /** |
| 2101 * Sets the `parent` property to `this` for the given [comment] and all the |
| 2102 * next tokens. |
| 2103 */ |
| 2104 void _setCommentParent(CommentToken comment) { |
| 2105 while (comment != null) { |
| 2106 comment.parent = this; |
| 2107 comment = comment.next; |
| 2108 } |
| 2109 } |
| 2110 |
| 2111 /** |
| 2086 * Compare the given [tokens] to find the token that appears first in the | 2112 * Compare the given [tokens] to find the token that appears first in the |
| 2087 * source being parsed. That is, return the left-most of all of the tokens. | 2113 * source being parsed. That is, return the left-most of all of the tokens. |
| 2088 * The list must be non-`null`, but the elements of the list are allowed to be | 2114 * The list must be non-`null`, but the elements of the list are allowed to be |
| 2089 * `null`. Return the token with the smallest offset, or `null` if the list is | 2115 * `null`. Return the token with the smallest offset, or `null` if the list is |
| 2090 * empty or if all of the elements of the list are `null`. | 2116 * empty or if all of the elements of the list are `null`. |
| 2091 */ | 2117 */ |
| 2092 static Token lexicallyFirst(List<Token> tokens) { | 2118 static Token lexicallyFirst(List<Token> tokens) { |
| 2093 Token first = null; | 2119 Token first = null; |
| 2094 int offset = -1; | 2120 int offset = -1; |
| 2095 for (Token token in tokens) { | 2121 for (Token token in tokens) { |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2565 String toString() => "-eof-"; | 2591 String toString() => "-eof-"; |
| 2566 } | 2592 } |
| 2567 | 2593 |
| 2568 /** | 2594 /** |
| 2569 * A `TokenWithComment` is a normal token that is preceded by comments. | 2595 * A `TokenWithComment` is a normal token that is preceded by comments. |
| 2570 */ | 2596 */ |
| 2571 class TokenWithComment extends Token { | 2597 class TokenWithComment extends Token { |
| 2572 /** | 2598 /** |
| 2573 * The first comment in the list of comments that precede this token. | 2599 * The first comment in the list of comments that precede this token. |
| 2574 */ | 2600 */ |
| 2575 CommentToken precedingComments; | 2601 CommentToken _precedingComment; |
| 2576 | 2602 |
| 2577 /** | 2603 /** |
| 2578 * Initialize a newly created token to have the given [type] at the given | 2604 * Initialize a newly created token to have the given [type] at the given |
| 2579 * [offset] and to be preceded by the comments reachable from the given | 2605 * [offset] and to be preceded by the comments reachable from the given |
| 2580 * [comment]. | 2606 * [comment]. |
| 2581 */ | 2607 */ |
| 2582 TokenWithComment(TokenType type, int offset, this.precedingComments) | 2608 TokenWithComment(TokenType type, int offset, this._precedingComment) |
| 2583 : super(type, offset) { | 2609 : super(type, offset) { |
| 2584 if (precedingComments != null) { | 2610 _setCommentParent(_precedingComment); |
| 2585 precedingComments.parent = this; | 2611 } |
| 2586 } | 2612 |
| 2613 CommentToken get precedingComments => _precedingComment; |
| 2614 |
| 2615 void set precedingComments(CommentToken comment) { |
| 2616 _precedingComment = comment; |
| 2617 _setCommentParent(_precedingComment); |
| 2587 } | 2618 } |
| 2588 | 2619 |
| 2589 @override | 2620 @override |
| 2590 Token copy() => new TokenWithComment(type, offset, precedingComments); | 2621 Token copy() => new TokenWithComment(type, offset, precedingComments); |
| 2591 } | 2622 } |
| OLD | NEW |