| 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 '../scanner.dart' show | 7 import '../scanner.dart' show |
| 8 Scanner; | 8 ErrorToken, |
| 9 Scanner, |
| 10 buildUnexpectedCharacterToken; |
| 11 |
| 12 import 'error_token.dart' show |
| 13 UnmatchedToken, |
| 14 UnterminatedToken; |
| 9 | 15 |
| 10 import 'keyword.dart' show | 16 import 'keyword.dart' show |
| 11 KeywordState, | 17 KeywordState, |
| 12 Keyword; | 18 Keyword; |
| 13 | 19 |
| 14 import 'precedence.dart'; | 20 import 'precedence.dart'; |
| 15 | 21 |
| 16 import 'token.dart' show | 22 import 'token.dart' show |
| 17 BadInputToken, | |
| 18 BeginGroupToken, | 23 BeginGroupToken, |
| 19 ErrorToken, | |
| 20 KeywordToken, | 24 KeywordToken, |
| 21 SymbolToken, | 25 SymbolToken, |
| 22 Token, | 26 Token; |
| 23 UnmatchedToken, | |
| 24 UnterminatedToken; | |
| 25 | 27 |
| 26 import 'token_constants.dart'; | 28 import 'token_constants.dart'; |
| 27 | 29 |
| 28 import 'characters.dart'; | 30 import 'characters.dart'; |
| 29 | 31 |
| 30 abstract class AbstractScanner implements Scanner { | 32 abstract class AbstractScanner implements Scanner { |
| 31 final bool includeComments; | 33 final bool includeComments; |
| 32 | 34 |
| 33 /** | 35 /** |
| 34 * The string offset for the next token that will be created. | 36 * The string offset for the next token that will be created. |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 389 |
| 388 if (identical(next, $EOF)) { | 390 if (identical(next, $EOF)) { |
| 389 return $EOF; | 391 return $EOF; |
| 390 } | 392 } |
| 391 if (next < 0x1f) { | 393 if (next < 0x1f) { |
| 392 return unexpected(next); | 394 return unexpected(next); |
| 393 } | 395 } |
| 394 | 396 |
| 395 next = currentAsUnicode(next); | 397 next = currentAsUnicode(next); |
| 396 | 398 |
| 397 // The following are non-ASCII characters. | |
| 398 | |
| 399 if (identical(next, $NBSP)) { | |
| 400 appendWhiteSpace(next); | |
| 401 return advance(); | |
| 402 } | |
| 403 | |
| 404 return unexpected(next); | 399 return unexpected(next); |
| 405 } | 400 } |
| 406 | 401 |
| 407 int tokenizeTag(int next) { | 402 int tokenizeTag(int next) { |
| 408 // # or #!.*[\n\r] | 403 // # or #!.*[\n\r] |
| 409 if (scanOffset == 0) { | 404 if (scanOffset == 0) { |
| 410 if (identical(peek(), $BANG)) { | 405 if (identical(peek(), $BANG)) { |
| 411 int start = scanOffset + 1; | 406 int start = scanOffset + 1; |
| 412 bool asciiOnly = true; | 407 bool asciiOnly = true; |
| 413 do { | 408 do { |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 asciiOnlyString = false; | 1061 asciiOnlyString = false; |
| 1067 asciiOnlyLine = false; | 1062 asciiOnlyLine = false; |
| 1068 } | 1063 } |
| 1069 next = advance(); | 1064 next = advance(); |
| 1070 } | 1065 } |
| 1071 if (!asciiOnlyLine) handleUnicode(unicodeStart); | 1066 if (!asciiOnlyLine) handleUnicode(unicodeStart); |
| 1072 return unterminatedMultiLineString(quoteChar); | 1067 return unterminatedMultiLineString(quoteChar); |
| 1073 } | 1068 } |
| 1074 | 1069 |
| 1075 int unexpected(int character) { | 1070 int unexpected(int character) { |
| 1076 appendErrorToken(new BadInputToken(character, tokenStart)); | 1071 appendErrorToken(buildUnexpectedCharacterToken(character, tokenStart)); |
| 1077 return advanceAfterError(true); | 1072 return advanceAfterError(true); |
| 1078 } | 1073 } |
| 1079 | 1074 |
| 1080 int unterminated(String prefix, {bool shouldAdvance: true}) { | 1075 int unterminated(String prefix, {bool shouldAdvance: true}) { |
| 1081 appendErrorToken(new UnterminatedToken(prefix, tokenStart, stringOffset)); | 1076 appendErrorToken(new UnterminatedToken(prefix, tokenStart, stringOffset)); |
| 1082 return advanceAfterError(shouldAdvance); | 1077 return advanceAfterError(shouldAdvance); |
| 1083 } | 1078 } |
| 1084 | 1079 |
| 1085 int unterminatedString(int quoteChar) { | 1080 int unterminatedString(int quoteChar) { |
| 1086 return unterminated(new String.fromCharCodes([quoteChar])); | 1081 return unterminated(new String.fromCharCodes([quoteChar])); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 | 1158 |
| 1164 PrecedenceInfo closeBraceInfoFor(BeginGroupToken begin) { | 1159 PrecedenceInfo closeBraceInfoFor(BeginGroupToken begin) { |
| 1165 return const { | 1160 return const { |
| 1166 '(': CLOSE_PAREN_INFO, | 1161 '(': CLOSE_PAREN_INFO, |
| 1167 '[': CLOSE_SQUARE_BRACKET_INFO, | 1162 '[': CLOSE_SQUARE_BRACKET_INFO, |
| 1168 '{': CLOSE_CURLY_BRACKET_INFO, | 1163 '{': CLOSE_CURLY_BRACKET_INFO, |
| 1169 '<': GT_INFO, | 1164 '<': GT_INFO, |
| 1170 r'${': CLOSE_CURLY_BRACKET_INFO, | 1165 r'${': CLOSE_CURLY_BRACKET_INFO, |
| 1171 }[begin.value]; | 1166 }[begin.value]; |
| 1172 } | 1167 } |
| OLD | NEW |