| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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.abstract_scanner; | 5 library fasta.scanner.abstract_scanner; |
| 6 | 6 |
| 7 import 'dart:collection' show ListMixin; | 7 import 'dart:collection' show ListMixin; |
| 8 | 8 |
| 9 import 'dart:typed_data' show Uint16List, Uint32List; | 9 import 'dart:typed_data' show Uint16List, Uint32List; |
| 10 | 10 |
| 11 import '../../scanner/token.dart' show Token, TokenType; | 11 import '../../scanner/token.dart' show BeginToken, Token, TokenType; |
| 12 | 12 |
| 13 import '../scanner.dart' | 13 import '../scanner.dart' |
| 14 show ErrorToken, Keyword, Scanner, buildUnexpectedCharacterToken; | 14 show ErrorToken, Keyword, Scanner, buildUnexpectedCharacterToken; |
| 15 | 15 |
| 16 import 'error_token.dart' show UnterminatedToken; | 16 import 'error_token.dart' show UnterminatedToken; |
| 17 | 17 |
| 18 import 'keyword_state.dart' show KeywordState; | 18 import 'keyword_state.dart' show KeywordState; |
| 19 | 19 |
| 20 import 'token.dart' | 20 import 'token.dart' show CommentToken, DartDocToken; |
| 21 show BeginGroupToken, CommentToken, DartDocToken, SymbolToken; | |
| 22 | 21 |
| 23 import 'token_constants.dart'; | 22 import 'token_constants.dart'; |
| 24 | 23 |
| 25 import 'characters.dart'; | 24 import 'characters.dart'; |
| 26 | 25 |
| 27 abstract class AbstractScanner implements Scanner { | 26 abstract class AbstractScanner implements Scanner { |
| 28 final bool includeComments; | 27 final bool includeComments; |
| 29 | 28 |
| 30 /** | 29 /** |
| 31 * A flag indicating whether to parse generic method comments, of the form | 30 * A flag indicating whether to parse generic method comments, of the form |
| (...skipping 10 matching lines...) Expand all Loading... |
| 42 */ | 41 */ |
| 43 int tokenStart = -1; | 42 int tokenStart = -1; |
| 44 | 43 |
| 45 /** | 44 /** |
| 46 * A pointer to the token stream created by this scanner. The first token | 45 * A pointer to the token stream created by this scanner. The first token |
| 47 * is a special token and not part of the source file. This is an | 46 * is a special token and not part of the source file. This is an |
| 48 * implementation detail to avoids special cases in the scanner. This token | 47 * implementation detail to avoids special cases in the scanner. This token |
| 49 * is not exposed to clients of the scanner, which are expected to invoke | 48 * is not exposed to clients of the scanner, which are expected to invoke |
| 50 * [firstToken] to access the token stream. | 49 * [firstToken] to access the token stream. |
| 51 */ | 50 */ |
| 52 final Token tokens = new SymbolToken.eof(-1); | 51 final Token tokens = new Token.eof(-1); |
| 53 | 52 |
| 54 /** | 53 /** |
| 55 * A pointer to the last scanned token. | 54 * A pointer to the last scanned token. |
| 56 */ | 55 */ |
| 57 Token tail; | 56 Token tail; |
| 58 | 57 |
| 59 /** | 58 /** |
| 60 * A pointer to the stream of comment tokens created by this scanner | 59 * A pointer to the stream of comment tokens created by this scanner |
| 61 * before they are assigned to the [Token] precedingComments field | 60 * before they are assigned to the [Token] precedingComments field |
| 62 * of a non-comment token. A value of `null` indicates no comment tokens. | 61 * of a non-comment token. A value of `null` indicates no comment tokens. |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 _appendToCommentStream(newComment); | 871 _appendToCommentStream(newComment); |
| 873 } | 872 } |
| 874 | 873 |
| 875 /** | 874 /** |
| 876 * Append the given token to the [tail] of the current stream of tokens. | 875 * Append the given token to the [tail] of the current stream of tokens. |
| 877 */ | 876 */ |
| 878 void appendToken(Token token) { | 877 void appendToken(Token token) { |
| 879 tail.next = token; | 878 tail.next = token; |
| 880 tail.next.previous = tail; | 879 tail.next.previous = tail; |
| 881 tail = tail.next; | 880 tail = tail.next; |
| 882 if (comments != null) { | 881 if (comments != null && comments == token.precedingComments) { |
| 882 comments = null; |
| 883 commentsTail = null; |
| 884 } else { |
| 883 // It is the responsibility of the caller to construct the token | 885 // It is the responsibility of the caller to construct the token |
| 884 // being appended with preceeding comments if any | 886 // being appended with preceeding comments if any |
| 885 assert(identical(token.precedingComments, comments)); | 887 assert(comments == null || token.isSynthetic); |
| 886 comments = null; | |
| 887 commentsTail = null; | |
| 888 } | 888 } |
| 889 } | 889 } |
| 890 | 890 |
| 891 void _appendToCommentStream(Token newComment) { | 891 void _appendToCommentStream(Token newComment) { |
| 892 if (comments == null) { | 892 if (comments == null) { |
| 893 comments = newComment; | 893 comments = newComment; |
| 894 commentsTail = comments; | 894 commentsTail = comments; |
| 895 } else { | 895 } else { |
| 896 commentsTail.next = newComment; | 896 commentsTail.next = newComment; |
| 897 commentsTail.next.previous = commentsTail; | 897 commentsTail.next.previous = commentsTail; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 int advanceAfterError(bool shouldAdvance) { | 1212 int advanceAfterError(bool shouldAdvance) { |
| 1213 if (atEndOfFile()) return $EOF; | 1213 if (atEndOfFile()) return $EOF; |
| 1214 if (shouldAdvance) { | 1214 if (shouldAdvance) { |
| 1215 return advance(); // Ensure progress. | 1215 return advance(); // Ensure progress. |
| 1216 } else { | 1216 } else { |
| 1217 return -1; | 1217 return -1; |
| 1218 } | 1218 } |
| 1219 } | 1219 } |
| 1220 } | 1220 } |
| 1221 | 1221 |
| 1222 TokenType closeBraceInfoFor(BeginGroupToken begin) { | 1222 TokenType closeBraceInfoFor(BeginToken begin) { |
| 1223 return const { | 1223 return const { |
| 1224 '(': TokenType.CLOSE_PAREN, | 1224 '(': TokenType.CLOSE_PAREN, |
| 1225 '[': TokenType.CLOSE_SQUARE_BRACKET, | 1225 '[': TokenType.CLOSE_SQUARE_BRACKET, |
| 1226 '{': TokenType.CLOSE_CURLY_BRACKET, | 1226 '{': TokenType.CLOSE_CURLY_BRACKET, |
| 1227 '<': TokenType.GT, | 1227 '<': TokenType.GT, |
| 1228 r'${': TokenType.CLOSE_CURLY_BRACKET, | 1228 r'${': TokenType.CLOSE_CURLY_BRACKET, |
| 1229 }[begin.lexeme]; | 1229 }[begin.lexeme]; |
| 1230 } | 1230 } |
| 1231 | 1231 |
| 1232 class LineStarts extends Object with ListMixin<int> { | 1232 class LineStarts extends Object with ListMixin<int> { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 switchToUint32(newLength); | 1298 switchToUint32(newLength); |
| 1299 } | 1299 } |
| 1300 } | 1300 } |
| 1301 | 1301 |
| 1302 void switchToUint32(int newLength) { | 1302 void switchToUint32(int newLength) { |
| 1303 final newArray = new Uint32List(newLength); | 1303 final newArray = new Uint32List(newLength); |
| 1304 newArray.setRange(0, arrayLength, array); | 1304 newArray.setRange(0, arrayLength, array); |
| 1305 array = newArray; | 1305 array = newArray; |
| 1306 } | 1306 } |
| 1307 } | 1307 } |
| OLD | NEW |