Chromium Code Reviews| 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 part of scanner; | 5 part of scanner; |
| 6 | 6 |
| 7 abstract class Scanner { | 7 abstract class Scanner { |
| 8 Token tokenize(); | 8 Token tokenize(); |
| 9 | 9 |
| 10 factory Scanner(SourceFile file, {bool includeComments: false}) { | 10 factory Scanner(SourceFile file, {bool includeComments: false}) { |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 next = advance(); // Advance past the $x or $X. | 621 next = advance(); // Advance past the $x or $X. |
| 622 bool hasDigits = false; | 622 bool hasDigits = false; |
| 623 while (true) { | 623 while (true) { |
| 624 next = advance(); | 624 next = advance(); |
| 625 if (($0 <= next && next <= $9) | 625 if (($0 <= next && next <= $9) |
| 626 || ($A <= next && next <= $F) | 626 || ($A <= next && next <= $F) |
| 627 || ($a <= next && next <= $f)) { | 627 || ($a <= next && next <= $f)) { |
| 628 hasDigits = true; | 628 hasDigits = true; |
| 629 } else { | 629 } else { |
| 630 if (!hasDigits) { | 630 if (!hasDigits) { |
| 631 return unterminated('0x'); | 631 unterminated('0x', shouldAdvance: false); |
| 632 return next; | |
| 632 } | 633 } |
| 633 appendSubstringToken(HEXADECIMAL_INFO, start, true); | 634 appendSubstringToken(HEXADECIMAL_INFO, start, true); |
| 634 return next; | 635 return next; |
| 635 } | 636 } |
| 636 } | 637 } |
| 637 return null; | 638 return null; |
| 638 } | 639 } |
| 639 | 640 |
| 640 int tokenizeDotsOrNumber(int next) { | 641 int tokenizeDotsOrNumber(int next) { |
| 641 int start = scanOffset; | 642 int start = scanOffset; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 return advance(); | 846 return advance(); |
| 846 } | 847 } |
| 847 | 848 |
| 848 int tokenizeString(int next, int start, bool raw) { | 849 int tokenizeString(int next, int start, bool raw) { |
| 849 int quoteChar = next; | 850 int quoteChar = next; |
| 850 next = advance(); | 851 next = advance(); |
| 851 if (identical(quoteChar, next)) { | 852 if (identical(quoteChar, next)) { |
| 852 next = advance(); | 853 next = advance(); |
| 853 if (identical(quoteChar, next)) { | 854 if (identical(quoteChar, next)) { |
| 854 // Multiline string. | 855 // Multiline string. |
| 855 return tokenizeMultiLineString(quoteChar, start, raw); | 856 return tokenizeMultiLineString(next, quoteChar, start, raw); |
| 856 } else { | 857 } else { |
| 857 // Empty string. | 858 // Empty string. |
| 858 appendSubstringToken(STRING_INFO, start, true); | 859 appendSubstringToken(STRING_INFO, start, true); |
| 859 return next; | 860 return next; |
| 860 } | 861 } |
| 861 } | 862 } |
| 862 if (raw) { | 863 if (raw) { |
| 863 return tokenizeSingleLineRawString(next, quoteChar, start); | 864 return tokenizeSingleLineRawString(next, quoteChar, start); |
| 864 } else { | 865 } else { |
| 865 return tokenizeSingleLineString(next, quoteChar, start); | 866 return tokenizeSingleLineString(next, quoteChar, start); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 next = tokenizeIdentifier(next, scanOffset, false); | 943 next = tokenizeIdentifier(next, scanOffset, false); |
| 943 } else { | 944 } else { |
| 944 unterminated(r'$', shouldAdvance: false); | 945 unterminated(r'$', shouldAdvance: false); |
| 945 } | 946 } |
| 946 beginToken(); // The string interpolation suffix starts here. | 947 beginToken(); // The string interpolation suffix starts here. |
| 947 return next; | 948 return next; |
| 948 } | 949 } |
| 949 | 950 |
| 950 int tokenizeSingleLineRawString(int next, int quoteChar, int start) { | 951 int tokenizeSingleLineRawString(int next, int quoteChar, int start) { |
| 951 bool asciiOnly = true; | 952 bool asciiOnly = true; |
| 952 next = advance(); // Advance past the quote. | |
|
ahe
2014/06/23 14:28:49
This line caused dart2js to incorrectly compile th
srawlins
2014/07/15 20:07:07
I disagree. In this example, I get the correct err
ahe
2014/07/16 07:54:18
What I'm trying to say is:
You removed this line.
srawlins
2014/08/12 04:32:58
Oh, I see! OK thank you. I've added your test as t
| |
| 953 while (next != $EOF) { | 953 while (next != $EOF) { |
| 954 if (identical(next, quoteChar)) { | 954 if (identical(next, quoteChar)) { |
| 955 if (!asciiOnly) handleUnicode(start); | 955 if (!asciiOnly) handleUnicode(start); |
| 956 next = advance(); | 956 next = advance(); |
| 957 appendSubstringToken(STRING_INFO, start, asciiOnly); | 957 appendSubstringToken(STRING_INFO, start, asciiOnly); |
| 958 return next; | 958 return next; |
| 959 } else if (identical(next, $LF) || identical(next, $CR)) { | 959 } else if (identical(next, $LF) || identical(next, $CR)) { |
| 960 if (!asciiOnly) handleUnicode(start); | 960 if (!asciiOnly) handleUnicode(start); |
| 961 return unterminatedRawString(quoteChar); | 961 return unterminatedRawString(quoteChar); |
| 962 } else if (next > 127) { | 962 } else if (next > 127) { |
| 963 asciiOnly = false; | 963 asciiOnly = false; |
| 964 } | 964 } |
| 965 next = advance(); | 965 next = advance(); |
| 966 } | 966 } |
| 967 if (!asciiOnly) handleUnicode(start); | 967 if (!asciiOnly) handleUnicode(start); |
| 968 return unterminatedRawString(quoteChar); | 968 return unterminatedRawString(quoteChar); |
| 969 } | 969 } |
| 970 | 970 |
| 971 int tokenizeMultiLineRawString(int quoteChar, int start) { | 971 int tokenizeMultiLineRawString(int next, int quoteChar, int start) { |
| 972 bool asciiOnlyString = true; | 972 bool asciiOnlyString = true; |
| 973 bool asciiOnlyLine = true; | 973 bool asciiOnlyLine = true; |
| 974 int unicodeStart = start; | 974 int unicodeStart = start; |
| 975 int next = advance(); // Advance past the (last) quote (of three). | 975 int next = advance(); // Advance past the (last) quote (of three). |
| 976 outer: while (!identical(next, $EOF)) { | 976 outer: while (!identical(next, $EOF)) { |
| 977 while (!identical(next, quoteChar)) { | 977 while (!identical(next, quoteChar)) { |
| 978 if (identical(next, $LF)) { | 978 if (identical(next, $LF)) { |
| 979 if (!asciiOnlyLine) { | 979 if (!asciiOnlyLine) { |
| 980 // Synchronize the string offset in the utf8 scanner. | 980 // Synchronize the string offset in the utf8 scanner. |
| 981 handleUnicode(unicodeStart); | 981 handleUnicode(unicodeStart); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 998 next = advance(); | 998 next = advance(); |
| 999 appendSubstringToken(STRING_INFO, start, asciiOnlyString); | 999 appendSubstringToken(STRING_INFO, start, asciiOnlyString); |
| 1000 return next; | 1000 return next; |
| 1001 } | 1001 } |
| 1002 } | 1002 } |
| 1003 } | 1003 } |
| 1004 if (!asciiOnlyLine) handleUnicode(unicodeStart); | 1004 if (!asciiOnlyLine) handleUnicode(unicodeStart); |
| 1005 return unterminatedRawMultiLineString(quoteChar); | 1005 return unterminatedRawMultiLineString(quoteChar); |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 int tokenizeMultiLineString(int quoteChar, int start, bool raw) { | 1008 int tokenizeMultiLineString(int next, int quoteChar, int start, bool raw) { |
|
ahe
2014/06/23 14:28:49
I don't understand this change.
srawlins
2014/07/15 20:07:08
Done. Sorry, I think from a previous fix.
| |
| 1009 if (raw) return tokenizeMultiLineRawString(quoteChar, start); | 1009 if (raw) return tokenizeMultiLineRawString(next, quoteChar, start); |
| 1010 bool asciiOnlyString = true; | 1010 bool asciiOnlyString = true; |
| 1011 bool asciiOnlyLine = true; | 1011 bool asciiOnlyLine = true; |
| 1012 int unicodeStart = start; | 1012 int unicodeStart = start; |
| 1013 int next = advance(); // Advance past the (last) quote (of three). | 1013 next = advance(); // Advance past the (last) quote (of three). |
| 1014 while (!identical(next, $EOF)) { | 1014 while (!identical(next, $EOF)) { |
| 1015 if (identical(next, $$)) { | 1015 if (identical(next, $$)) { |
| 1016 if (!asciiOnlyLine) handleUnicode(unicodeStart); | 1016 if (!asciiOnlyLine) handleUnicode(unicodeStart); |
| 1017 next = tokenizeStringInterpolation(start, asciiOnlyString); | 1017 next = tokenizeStringInterpolation(start, asciiOnlyString); |
| 1018 start = scanOffset; | 1018 start = scanOffset; |
| 1019 unicodeStart = start; | 1019 unicodeStart = start; |
| 1020 asciiOnlyString = true; // A new string token is created for the rest. | 1020 asciiOnlyString = true; // A new string token is created for the rest. |
| 1021 asciiOnlyLine = true; | 1021 asciiOnlyLine = true; |
| 1022 continue; | 1022 continue; |
| 1023 } | 1023 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 } | 1071 } |
| 1072 | 1072 |
| 1073 int unterminatedRawString(int quoteChar) { | 1073 int unterminatedRawString(int quoteChar) { |
| 1074 return unterminated('r${new String.fromCharCodes([quoteChar])}'); | 1074 return unterminated('r${new String.fromCharCodes([quoteChar])}'); |
| 1075 } | 1075 } |
| 1076 | 1076 |
| 1077 int unterminatedMultiLineString(int quoteChar) { | 1077 int unterminatedMultiLineString(int quoteChar) { |
| 1078 return unterminated( | 1078 return unterminated( |
| 1079 new String.fromCharCodes([quoteChar, quoteChar, quoteChar])); | 1079 new String.fromCharCodes([quoteChar, quoteChar, quoteChar])); |
| 1080 } | 1080 } |
| 1081 | |
| 1081 int unterminatedRawMultiLineString(int quoteChar) { | 1082 int unterminatedRawMultiLineString(int quoteChar) { |
| 1082 return unterminated( | 1083 return unterminated( |
| 1083 'r${new String.fromCharCodes([quoteChar, quoteChar, quoteChar])}'); | 1084 'r${new String.fromCharCodes([quoteChar, quoteChar, quoteChar])}'); |
| 1084 } | 1085 } |
| 1085 | 1086 |
| 1086 int advanceAfterError(bool shouldAdvance) { | 1087 int advanceAfterError(bool shouldAdvance) { |
| 1087 if (atEndOfFile()) return $EOF; | 1088 if (atEndOfFile()) return $EOF; |
| 1088 if (shouldAdvance) { | 1089 if (shouldAdvance) { |
| 1089 return advance(); // Ensure progress. | 1090 return advance(); // Ensure progress. |
| 1090 } else { | 1091 } else { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1146 | 1147 |
| 1147 PrecedenceInfo closeBraceInfoFor(BeginGroupToken begin) { | 1148 PrecedenceInfo closeBraceInfoFor(BeginGroupToken begin) { |
| 1148 return const { | 1149 return const { |
| 1149 '(': CLOSE_PAREN_INFO, | 1150 '(': CLOSE_PAREN_INFO, |
| 1150 '[': CLOSE_SQUARE_BRACKET_INFO, | 1151 '[': CLOSE_SQUARE_BRACKET_INFO, |
| 1151 '{': CLOSE_CURLY_BRACKET_INFO, | 1152 '{': CLOSE_CURLY_BRACKET_INFO, |
| 1152 '<': GT_INFO, | 1153 '<': GT_INFO, |
| 1153 r'${': CLOSE_CURLY_BRACKET_INFO, | 1154 r'${': CLOSE_CURLY_BRACKET_INFO, |
| 1154 }[begin.value]; | 1155 }[begin.value]; |
| 1155 } | 1156 } |
| OLD | NEW |