| 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 abstract class Scanner { | 5 abstract class Scanner { |
| 6 Token tokenize(); | 6 Token tokenize(); |
| 7 } | 7 } |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Common base class for a Dart scanner. | 10 * Common base class for a Dart scanner. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 return firstToken(); | 99 return firstToken(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 int bigSwitch(int next) { | 102 int bigSwitch(int next) { |
| 103 beginToken(); | 103 beginToken(); |
| 104 if (next === $TAB || next === $LF || next === $CR || next === $SPACE) { | 104 if (next === $TAB || next === $LF || next === $CR || next === $SPACE) { |
| 105 appendWhiteSpace(next); | 105 appendWhiteSpace(next); |
| 106 return advance(); | 106 return advance(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 if ($r === next) { |
| 110 return tokenizeRawStringKeywordOrIdentifier(next); |
| 111 } |
| 112 |
| 109 if ($a <= next && next <= $z) { | 113 if ($a <= next && next <= $z) { |
| 110 return tokenizeKeywordOrIdentifier(next, true); | 114 return tokenizeKeywordOrIdentifier(next, true); |
| 111 } | 115 } |
| 112 | 116 |
| 113 if (($A <= next && next <= $Z) || next === $_ || next === $$) { | 117 if (($A <= next && next <= $Z) || next === $_ || next === $$) { |
| 114 return tokenizeIdentifier(next, byteOffset, true); | 118 return tokenizeIdentifier(next, byteOffset, true); |
| 115 } | 119 } |
| 116 | 120 |
| 117 if (next === $LT) { | 121 if (next === $LT) { |
| 118 return tokenizeLessThan(next); | 122 return tokenizeLessThan(next); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 227 |
| 224 if (next === $CLOSE_CURLY_BRACKET) { | 228 if (next === $CLOSE_CURLY_BRACKET) { |
| 225 return appendEndGroup(CLOSE_CURLY_BRACKET_INFO, "}", | 229 return appendEndGroup(CLOSE_CURLY_BRACKET_INFO, "}", |
| 226 OPEN_CURLY_BRACKET_TOKEN); | 230 OPEN_CURLY_BRACKET_TOKEN); |
| 227 } | 231 } |
| 228 | 232 |
| 229 if (next === $SLASH) { | 233 if (next === $SLASH) { |
| 230 return tokenizeSlashOrComment(next); | 234 return tokenizeSlashOrComment(next); |
| 231 } | 235 } |
| 232 | 236 |
| 237 // TODO(aprelev@gmail.com) Remove deprecated raw string literals |
| 233 if (next === $AT) { | 238 if (next === $AT) { |
| 234 return tokenizeAtOrRawString(next); | 239 return tokenizeAtOrRawString(next); |
| 235 } | 240 } |
| 236 | 241 |
| 237 if (next === $DQ || next === $SQ) { | 242 if (next === $DQ || next === $SQ) { |
| 238 return tokenizeString(next, byteOffset, false); | 243 return tokenizeString(next, byteOffset, false); |
| 239 } | 244 } |
| 240 | 245 |
| 241 if (next === $PERIOD) { | 246 if (next === $PERIOD) { |
| 242 return tokenizeDotsOrNumber(next); | 247 return tokenizeDotsOrNumber(next); |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 if ($STAR === next) { | 618 if ($STAR === next) { |
| 614 next = advance(); | 619 next = advance(); |
| 615 ++nesting; | 620 ++nesting; |
| 616 } | 621 } |
| 617 } else { | 622 } else { |
| 618 next = advance(); | 623 next = advance(); |
| 619 } | 624 } |
| 620 } | 625 } |
| 621 } | 626 } |
| 622 | 627 |
| 628 int tokenizeRawStringKeywordOrIdentifier(int next) { |
| 629 int nextnext = peek(); |
| 630 if (nextnext === $DQ || nextnext === $SQ) { |
| 631 int start = byteOffset; |
| 632 next = advance(); |
| 633 return tokenizeString(next, start, true); |
| 634 } |
| 635 return tokenizeKeywordOrIdentifier(next, true); |
| 636 } |
| 637 |
| 623 int tokenizeKeywordOrIdentifier(int next, bool allowDollar) { | 638 int tokenizeKeywordOrIdentifier(int next, bool allowDollar) { |
| 624 KeywordState state = KeywordState.KEYWORD_STATE; | 639 KeywordState state = KeywordState.KEYWORD_STATE; |
| 625 int start = byteOffset; | 640 int start = byteOffset; |
| 626 while (state !== null && $a <= next && next <= $z) { | 641 while (state !== null && $a <= next && next <= $z) { |
| 627 state = state.next(next); | 642 state = state.next(next); |
| 628 next = advance(); | 643 next = advance(); |
| 629 } | 644 } |
| 630 if (state === null || state.keyword === null) { | 645 if (state === null || state.keyword === null) { |
| 631 return tokenizeIdentifier(next, start, allowDollar); | 646 return tokenizeIdentifier(next, start, allowDollar); |
| 632 } | 647 } |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 next = advance(); | 868 next = advance(); |
| 854 } | 869 } |
| 855 return error(const SourceString("unterminated string literal")); | 870 return error(const SourceString("unterminated string literal")); |
| 856 } | 871 } |
| 857 | 872 |
| 858 int error(SourceString message) { | 873 int error(SourceString message) { |
| 859 appendByteStringToken(BAD_INPUT_INFO, message); | 874 appendByteStringToken(BAD_INPUT_INFO, message); |
| 860 return advance(); // Ensure progress. | 875 return advance(); // Ensure progress. |
| 861 } | 876 } |
| 862 } | 877 } |
| OLD | NEW |