Add fasta parser argument list recovery

Change-Id: Ic45e95a130eb01f6bd8d390607e2b110bc8f9d99
Reviewed-on: https://dart-review.googlesource.com/22760
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
This commit is contained in:
Dan Rubel 2017-11-21 22:05:17 +00:00 committed by commit-bot@chromium.org
parent 37cd5e33ce
commit bac8cf868c
3 changed files with 18 additions and 22 deletions

View file

@ -357,14 +357,6 @@ class ErrorParserTest_Fasta extends FastaParserTestCase
super.test_expectedStringLiteral();
}
@override
@failingTest
void test_expectedToken_commaMissingInArgumentList() {
// TODO(brianwilkerson) Wrong errors:
// Expected 1 errors of type ParserErrorCode.EXPECTED_TOKEN, found 0
super.test_expectedToken_commaMissingInArgumentList();
}
@override
@failingTest
void test_expectedToken_parseStatement_afterVoid() {
@ -2891,13 +2883,6 @@ class RecoveryParserTest_Fasta extends FastaParserTestCase
super.test_keywordInPlaceOfIdentifier();
}
@override
@failingTest
void test_missing_commaInArgumentList() {
// TODO(brianwilkerson) reportUnrecoverableErrorWithToken
super.test_missing_commaInArgumentList();
}
@override
@failingTest
void test_missingComma_beforeNamedArgument() {

View file

@ -2894,8 +2894,9 @@ class Foo {
createParser('(x, y z)');
ArgumentList list = parser.parseArgumentList();
expectNotNullIfNoErrors(list);
listener
.assertErrors([expectedError(ParserErrorCode.EXPECTED_TOKEN, 4, 1)]);
listener.assertErrors(usingFastaParser
? [expectedError(ParserErrorCode.UNEXPECTED_TOKEN, 6, 1)]
: [expectedError(ParserErrorCode.EXPECTED_TOKEN, 4, 1)]);
}
void test_expectedToken_parseStatement_afterVoid() {
@ -10527,7 +10528,10 @@ class C<K {
}
void test_missing_commaInArgumentList() {
parseExpression("f(x: 1 y: 2)", codes: [ParserErrorCode.EXPECTED_TOKEN]);
parseExpression("f(x: 1 y: 2)",
codes: usingFastaParser
? [ParserErrorCode.UNEXPECTED_TOKEN]
: [ParserErrorCode.EXPECTED_TOKEN]);
}
void test_missingComma_beforeNamedArgument() {

View file

@ -4965,7 +4965,7 @@ class Parser {
bool hasSeenNamedArgument = false;
bool old = mayParseFunctionExpressions;
mayParseFunctionExpressions = true;
do {
while (true) {
Token next = token.next;
if (optional(')', next)) {
token = next;
@ -4982,13 +4982,20 @@ class Parser {
// Positional argument after named argument.
reportRecoverableError(next, fasta.messagePositionalAfterNamedArgument);
}
token = parseExpression(token.next).next;
token = parseExpression(token.next);
next = token.next;
if (colon != null) listener.handleNamedArgument(colon);
++argumentCount;
} while (optional(',', token));
if (optional(',', next)) {
token = next;
continue;
}
token = ensureCloseParen(token, begin);
break;
}
assert(optional(')', token));
mayParseFunctionExpressions = old;
listener.endArguments(argumentCount, begin, token);
expect(')', token);
return token;
}