Skip to content

Commit c62bd8f

Browse files
Dan Rubelcommit-bot@chromium.org
authored andcommitted
prepend unterminated comment error token and others
Change-Id: I18fd270e9b74e1fd94403ef90f275001983aa86d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110180 Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 34ed30f commit c62bd8f

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

pkg/front_end/lib/src/fasta/scanner/abstract_scanner.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ abstract class AbstractScanner implements Scanner {
11721172
} else {
11731173
if (!hasExponentDigits) {
11741174
appendSyntheticSubstringToken(TokenType.DOUBLE, start, true, '0');
1175-
appendErrorToken(new UnterminatedToken(
1175+
prependErrorToken(new UnterminatedToken(
11761176
messageMissingExponent, tokenStart, stringOffset));
11771177
return next;
11781178
}
@@ -1353,7 +1353,9 @@ abstract class AbstractScanner implements Scanner {
13531353
while (true) {
13541354
if (identical($EOF, next)) {
13551355
if (!asciiOnlyLines) handleUnicode(unicodeStart);
1356-
unterminated(messageUnterminatedComment);
1356+
prependErrorToken(UnterminatedToken(
1357+
messageUnterminatedComment, tokenStart, stringOffset));
1358+
advanceAfterError(true);
13571359
break;
13581360
} else if (identical($STAR, next)) {
13591361
next = advance();
@@ -1623,7 +1625,8 @@ abstract class AbstractScanner implements Scanner {
16231625
} else {
16241626
beginToken(); // The synthetic identifier starts here.
16251627
appendSyntheticSubstringToken(TokenType.IDENTIFIER, scanOffset, true, '');
1626-
unterminated(messageUnexpectedDollarInString, shouldAdvance: false);
1628+
prependErrorToken(UnterminatedToken(
1629+
messageUnexpectedDollarInString, tokenStart, stringOffset));
16271630
}
16281631
beginToken(); // The string interpolation suffix starts here.
16291632
return next;
@@ -1752,11 +1755,6 @@ abstract class AbstractScanner implements Scanner {
17521755
return advanceAfterError(true);
17531756
}
17541757

1755-
int unterminated(Message message, {bool shouldAdvance: true}) {
1756-
appendErrorToken(new UnterminatedToken(message, tokenStart, stringOffset));
1757-
return advanceAfterError(shouldAdvance);
1758-
}
1759-
17601758
void unterminatedString(int quoteChar, int quoteStart, int start,
17611759
{bool asciiOnly, bool isMultiLine, bool isRaw}) {
17621760
String suffix = new String.fromCharCodes(

pkg/front_end/lib/src/fasta/scanner/recover.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Token scannerRecovery(List<int> bytes, Token tokens, List<int> lineStarts) {
126126
}
127127

128128
recoverExponent() {
129-
return errorTail.next;
129+
throw "Internal error: Exponent error token should have been prepended";
130130
}
131131

132132
recoverString() {
@@ -138,12 +138,11 @@ Token scannerRecovery(List<int> bytes, Token tokens, List<int> lineStarts) {
138138
}
139139

140140
recoverStringInterpolation() {
141-
return errorTail.next;
141+
throw "Internal error: Interpolation error token should have been prepended";
142142
}
143143

144144
recoverComment() {
145-
// TODO(ahe): Improve this.
146-
return skipToEof(errorTail);
145+
throw "Internal error: Comment error token should have been prepended";
147146
}
148147

149148
recoverUnmatched() {
@@ -156,7 +155,10 @@ Token scannerRecovery(List<int> bytes, Token tokens, List<int> lineStarts) {
156155
Token current = tokens;
157156
while (current is ErrorToken &&
158157
(current.errorCode == codeExpectedHexDigit ||
158+
current.errorCode == codeUnexpectedDollarInString ||
159+
current.errorCode == codeMissingExponent ||
159160
current.errorCode == codeUnmatchedToken ||
161+
current.errorCode == codeUnterminatedComment ||
160162
current.errorCode == codeUnterminatedString)) {
161163
if (errorTail == null) {
162164
error = current;

pkg/front_end/lib/src/scanner/errors.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,16 @@ void translateErrorToken(ErrorToken token, ReportError reportError) {
118118
case "UNTERMINATED_STRING_LITERAL":
119119
// TODO(paulberry,ahe): Fasta reports the error location as the entire
120120
// string; analyzer expects the end of the string.
121-
// TODO(danrubel): Remove this once all analyzer clients
122-
// can process errors via the scanner's errors list.
123121
reportError(
124122
ScannerErrorCode.UNTERMINATED_STRING_LITERAL, endOffset - 1, null);
125123
return;
126124

127125
case "UNTERMINATED_MULTI_LINE_COMMENT":
128126
// TODO(paulberry,ahe): Fasta reports the error location as the entire
129127
// comment; analyzer expects the end of the comment.
130-
charOffset = endOffset;
131-
return _makeError(ScannerErrorCode.UNTERMINATED_MULTI_LINE_COMMENT, null);
128+
reportError(ScannerErrorCode.UNTERMINATED_MULTI_LINE_COMMENT,
129+
endOffset - 1, null);
130+
return;
132131

133132
case "MISSING_DIGIT":
134133
// TODO(paulberry,ahe): Fasta reports the error location as the entire

pkg/front_end/test/scanner_fasta_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,13 @@ abstract class ScannerTest_Fasta_Base {
501501

502502
void test_string_simple_missing_interpolation_identifier() {
503503
Token token = scan(r'"foo $');
504-
expect((token as fasta.ErrorToken).errorCode, same(codeUnterminatedString));
505-
expect((token as fasta.UnterminatedString).start, '"');
506-
507-
token = token.next;
508504
expect((token as fasta.ErrorToken).errorCode,
509505
same(codeUnexpectedDollarInString));
510506

507+
token = token.next;
508+
expect((token as fasta.ErrorToken).errorCode, same(codeUnterminatedString));
509+
expect((token as fasta.UnterminatedString).start, '"');
510+
511511
token = token.next;
512512
expectToken(token, TokenType.STRING, 0, 5, lexeme: '"foo ');
513513

0 commit comments

Comments
 (0)