mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:21:07 +00:00
prepend missing hex digits error token
This prepends (rather than append) another error token to the token stream similar to https://dart-review.googlesource.com/c/sdk/+/110100 In addition, this addresses a comment in https://dart-review.googlesource.com/c/sdk/+/110140 Change-Id: I27c739b0ee3213cdbce92c3ff18c31fde862251c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110141 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Dan Rubel <danrubel@google.com>
This commit is contained in:
parent
62674b977d
commit
9c148623c5
|
@ -1062,6 +1062,17 @@ main() { // missing async
|
|||
]);
|
||||
}
|
||||
|
||||
void test_constructor_this_cascade_synthetic() {
|
||||
// https://github.com/dart-lang/sdk/issues/37110
|
||||
parseCompilationUnit('class B extends A { B(): this.. {} }', errors: [
|
||||
expectedError(ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER, 25, 4),
|
||||
expectedError(ParserErrorCode.EXPECTED_TOKEN, 29, 2),
|
||||
expectedError(ParserErrorCode.MISSING_IDENTIFIER, 32, 1),
|
||||
expectedError(ParserErrorCode.MISSING_FUNCTION_BODY, 33, 1),
|
||||
expectedError(ParserErrorCode.EXPECTED_EXECUTABLE, 35, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
void test_constructor_this_field() {
|
||||
// https://github.com/dart-lang/sdk/issues/36262
|
||||
// https://github.com/dart-lang/sdk/issues/31198
|
||||
|
|
|
@ -26,7 +26,8 @@ import 'error_token.dart'
|
|||
|
||||
import 'keyword_state.dart' show KeywordState;
|
||||
|
||||
import 'token.dart' show CommentToken, DartDocToken, LanguageVersionToken;
|
||||
import 'token.dart'
|
||||
show CommentToken, DartDocToken, LanguageVersionToken, SyntheticStringToken;
|
||||
|
||||
import 'token_constants.dart';
|
||||
|
||||
|
@ -247,6 +248,9 @@ abstract class AbstractScanner implements Scanner {
|
|||
/// Append [token] to the token stream.
|
||||
void appendErrorToken(ErrorToken token);
|
||||
|
||||
/// Prepend [token] to the token stream.
|
||||
void prependErrorToken(ErrorToken token);
|
||||
|
||||
/**
|
||||
* Returns a new comment from the scan offset [start] to the current
|
||||
* [scanOffset] plus the [extraOffset]. For example, if the current
|
||||
|
@ -790,7 +794,11 @@ abstract class AbstractScanner implements Scanner {
|
|||
hasDigits = true;
|
||||
} else {
|
||||
if (!hasDigits) {
|
||||
unterminated(messageExpectedHexDigit, shouldAdvance: false);
|
||||
prependErrorToken(new UnterminatedToken(
|
||||
messageExpectedHexDigit, start, stringOffset));
|
||||
// Recovery
|
||||
// TODO(danrubel): append actual characters not "0"
|
||||
appendToken(SyntheticStringToken(TokenType.INT, "0", tokenStart));
|
||||
return next;
|
||||
}
|
||||
appendSubstringToken(TokenType.HEXADECIMAL, start, true);
|
||||
|
|
|
@ -260,6 +260,7 @@ abstract class ArrayBasedScanner extends AbstractScanner {
|
|||
appendToken(token);
|
||||
}
|
||||
|
||||
@override
|
||||
void prependErrorToken(ErrorToken token) {
|
||||
hasErrors = true;
|
||||
if (_errorTail == tail) {
|
||||
|
|
|
@ -135,8 +135,7 @@ Token scannerRecovery(List<int> bytes, Token tokens, List<int> lineStarts) {
|
|||
}
|
||||
|
||||
recoverHexDigit() {
|
||||
return synthesizeToken(errorTail.charOffset, "0", TokenType.INT)
|
||||
..setNext(errorTail.next);
|
||||
throw "Internal error: Hex digit error token should have been prepended";
|
||||
}
|
||||
|
||||
recoverStringInterpolation() {
|
||||
|
@ -156,7 +155,9 @@ Token scannerRecovery(List<int> bytes, Token tokens, List<int> lineStarts) {
|
|||
|
||||
// All unmatched error tokens should have been prepended
|
||||
Token current = tokens;
|
||||
while (current is ErrorToken && current.errorCode == codeUnmatchedToken) {
|
||||
while (current is ErrorToken &&
|
||||
(current.errorCode == codeUnmatchedToken ||
|
||||
current.errorCode == codeExpectedHexDigit)) {
|
||||
if (errorTail == null) {
|
||||
error = current;
|
||||
}
|
||||
|
|
|
@ -303,7 +303,7 @@ abstract class ScannerTestBase {
|
|||
}
|
||||
|
||||
void test_hexadecimal_missingDigit() {
|
||||
_assertError(ScannerErrorCode.MISSING_HEX_DIGIT, 1, "0x");
|
||||
_assertError(ScannerErrorCode.MISSING_HEX_DIGIT, 5, "a = 0x");
|
||||
}
|
||||
|
||||
void test_identifier() {
|
||||
|
|
Loading…
Reference in a new issue