| Index: pkg/front_end/lib/src/fasta/parser/parser.dart
|
| diff --git a/pkg/front_end/lib/src/fasta/parser/parser.dart b/pkg/front_end/lib/src/fasta/parser/parser.dart
|
| index 5158f046ec9efa7fc51149ea1d5a9b671d96d591..ae5a119d0773a06a49d0bca292296c24e9b92f18 100644
|
| --- a/pkg/front_end/lib/src/fasta/parser/parser.dart
|
| +++ b/pkg/front_end/lib/src/fasta/parser/parser.dart
|
| @@ -4,7 +4,8 @@
|
|
|
| library fasta.parser.parser;
|
|
|
| -import '../fasta_codes.dart' show FastaCode, FastaMessage;
|
| +import '../fasta_codes.dart'
|
| + show BoundFastaCode, BoundFastaMessage, FastaCode, FastaMessage;
|
|
|
| import '../fasta_codes.dart' as fasta;
|
|
|
| @@ -613,7 +614,7 @@ class Parser {
|
| token =
|
| parseQualifiedRestOpt(token, IdentifierContext.metadataContinuation);
|
| if (optional("<", token)) {
|
| - reportRecoverableErrorCode(token, fasta.codeMetadataTypeArguments);
|
| + reportRecoverableError(token, fasta.codeMetadataTypeArguments);
|
| }
|
| token = parseTypeArgumentsOpt(token);
|
| Token period = null;
|
| @@ -678,11 +679,10 @@ class Parser {
|
| listener.beginOptionalFormalParameters(token);
|
| if (!optional('(', token)) {
|
| if (optional(';', token)) {
|
| - reportRecoverableErrorCode(token, fasta.codeExpectedOpenParens);
|
| + reportRecoverableError(token, fasta.codeExpectedOpenParens);
|
| return token;
|
| }
|
| - return reportUnrecoverableErrorCodeWithString(
|
| - token, fasta.codeExpectedButGot, "(")
|
| + return reportUnrecoverableError(token, fasta.codeExpectedButGot.bind("("))
|
| .next;
|
| }
|
| BeginToken beginGroupToken = token;
|
| @@ -715,7 +715,7 @@ class Parser {
|
| break;
|
| } else if (identical(value, '[]')) {
|
| --parameterCount;
|
| - reportRecoverableErrorCode(token, fasta.codeEmptyOptionalParameterList);
|
| + reportRecoverableError(token, fasta.codeEmptyOptionalParameterList);
|
| token = token.next;
|
| break;
|
| }
|
| @@ -752,7 +752,7 @@ class Parser {
|
| ++parameterCount;
|
| } while (optional(',', token));
|
| if (parameterCount == 0) {
|
| - reportRecoverableErrorCode(
|
| + reportRecoverableError(
|
| token,
|
| isNamed
|
| ? fasta.codeEmptyNamedParameterList
|
| @@ -885,7 +885,7 @@ class Parser {
|
|
|
| Token skipBlock(Token token) {
|
| if (!optional('{', token)) {
|
| - return reportUnrecoverableErrorCode(token, fasta.codeExpectedBlockToSkip)
|
| + return reportUnrecoverableError(token, fasta.codeExpectedBlockToSkip)
|
| .next;
|
| }
|
| BeginToken beginGroupToken = token;
|
| @@ -989,7 +989,7 @@ class Parser {
|
| Token parseStringPart(Token token) {
|
| if (token.kind != STRING_TOKEN) {
|
| token =
|
| - reportUnrecoverableErrorCodeWithToken(token, fasta.codeExpectedString)
|
| + reportUnrecoverableError(token, fasta.codeExpectedString.bind(token))
|
| .next;
|
| }
|
| listener.handleStringPart(token);
|
| @@ -999,27 +999,27 @@ class Parser {
|
| Token parseIdentifier(Token token, IdentifierContext context) {
|
| if (!token.isIdentifier) {
|
| if (optional("void", token)) {
|
| - reportRecoverableErrorCode(token, fasta.codeInvalidVoid);
|
| + reportRecoverableError(token, fasta.codeInvalidVoid);
|
| } else {
|
| - token = reportUnrecoverableErrorCodeWithToken(
|
| - token, fasta.codeExpectedIdentifier)
|
| + token = reportUnrecoverableError(
|
| + token, fasta.codeExpectedIdentifier.bind(token))
|
| .next;
|
| }
|
| } else if (token.type.isBuiltIn && !context.isBuiltInIdentifierAllowed) {
|
| if (context.inDeclaration) {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeBuiltInIdentifierInDeclaration);
|
| + reportRecoverableError(
|
| + token, fasta.codeBuiltInIdentifierInDeclaration.bind(token));
|
| } else if (!optional("dynamic", token)) {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeBuiltInIdentifierAsType);
|
| + reportRecoverableError(
|
| + token, fasta.codeBuiltInIdentifierAsType.bind(token));
|
| }
|
| } else if (!inPlainSync && token.type.isPseudo) {
|
| if (optional('await', token)) {
|
| - reportRecoverableErrorCode(token, fasta.codeAwaitAsIdentifier);
|
| + reportRecoverableError(token, fasta.codeAwaitAsIdentifier);
|
| } else if (optional('yield', token)) {
|
| - reportRecoverableErrorCode(token, fasta.codeYieldAsIdentifier);
|
| + reportRecoverableError(token, fasta.codeYieldAsIdentifier);
|
| } else if (optional('async', token)) {
|
| - reportRecoverableErrorCode(token, fasta.codeAsyncAsIdentifier);
|
| + reportRecoverableError(token, fasta.codeAsyncAsIdentifier);
|
| }
|
| }
|
| listener.handleIdentifier(token, context);
|
| @@ -1028,8 +1028,8 @@ class Parser {
|
|
|
| Token expect(String string, Token token) {
|
| if (!identical(string, token.stringValue)) {
|
| - return reportUnrecoverableErrorCodeWithString(
|
| - token, fasta.codeExpectedButGot, string)
|
| + return reportUnrecoverableError(
|
| + token, fasta.codeExpectedButGot.bind(string))
|
| .next;
|
| }
|
| return token.next;
|
| @@ -1248,7 +1248,7 @@ class Parser {
|
| }
|
|
|
| if (hasVar) {
|
| - reportRecoverableErrorCode(begin, fasta.codeTypeAfterVar);
|
| + reportRecoverableError(begin, fasta.codeTypeAfterVar);
|
| }
|
|
|
| return token;
|
| @@ -1460,8 +1460,7 @@ class Parser {
|
| }
|
| if (isNamedParameter && nameToken.lexeme.startsWith("_")) {
|
| // TODO(ahe): Move this to after commiting the type.
|
| - reportRecoverableErrorCode(
|
| - nameToken, fasta.codePrivateNamedParameter);
|
| + reportRecoverableError(nameToken, fasta.codePrivateNamedParameter);
|
| }
|
|
|
| token = listener.injectGenericCommentTypeList(token);
|
| @@ -1502,7 +1501,7 @@ class Parser {
|
| // The following isn't allowed:
|
| // int Function(int bar(String x)).
|
| if (memberKind == MemberKind.GeneralizedFunctionType) {
|
| - reportRecoverableErrorCode(
|
| + reportRecoverableError(
|
| inlineFunctionTypeStart, fasta.codeInvalidInlineFunctionType);
|
| }
|
| } else if (untyped) {
|
| @@ -1525,15 +1524,15 @@ class Parser {
|
| token = parseExpression(token.next);
|
| listener.handleValuedFormalParameter(equal, token);
|
| if (parameterKind.isRequired) {
|
| - reportRecoverableErrorCode(
|
| + reportRecoverableError(
|
| equal, fasta.codeRequiredParameterWithDefault);
|
| } else if (parameterKind.isPositional && identical(':', value)) {
|
| - reportRecoverableErrorCode(
|
| + reportRecoverableError(
|
| equal, fasta.codePositionalParameterWithEquals);
|
| } else if (inFunctionType ||
|
| memberKind == MemberKind.FunctionTypeAlias ||
|
| memberKind == MemberKind.FunctionTypedParameter) {
|
| - reportRecoverableErrorCode(
|
| + reportRecoverableError(
|
| equal.next, fasta.codeFunctionTypeDefaultValue);
|
| }
|
| } else {
|
| @@ -1597,16 +1596,16 @@ class Parser {
|
|
|
| Link<Token> identifiers = findMemberName(token);
|
| if (identifiers.isEmpty) {
|
| - return reportUnrecoverableErrorCodeWithToken(
|
| - start, fasta.codeExpectedDeclaration)
|
| + return reportUnrecoverableError(
|
| + start, fasta.codeExpectedDeclaration.bind(start))
|
| .next;
|
| }
|
| Token afterName = identifiers.head;
|
| identifiers = identifiers.tail;
|
|
|
| if (identifiers.isEmpty) {
|
| - return reportUnrecoverableErrorCodeWithToken(
|
| - start, fasta.codeExpectedDeclaration)
|
| + return reportUnrecoverableError(
|
| + start, fasta.codeExpectedDeclaration.bind(start))
|
| .next;
|
| }
|
| Token name = identifiers.head;
|
| @@ -1678,7 +1677,7 @@ class Parser {
|
| isVarAllowed: true);
|
|
|
| if (token != name) {
|
| - reportRecoverableErrorCodeWithToken(token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(token, fasta.codeExtraneousModifier.bind(token));
|
| token = name;
|
| }
|
|
|
| @@ -1716,8 +1715,8 @@ class Parser {
|
| if (externalModifier == null && optional('external', modifier)) {
|
| externalModifier = modifier;
|
| } else {
|
| - reportRecoverableErrorCodeWithToken(
|
| - modifier, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + modifier, fasta.codeExtraneousModifier.bind(modifier));
|
| }
|
| }
|
| if (externalModifier != null) {
|
| @@ -1748,7 +1747,7 @@ class Parser {
|
| Token asyncToken = token;
|
| token = parseAsyncModifier(token);
|
| if (getOrSet != null && !inPlainSync && optional("set", getOrSet)) {
|
| - reportRecoverableErrorCode(asyncToken, fasta.codeSetterNotSync);
|
| + reportRecoverableError(asyncToken, fasta.codeSetterNotSync);
|
| }
|
| token = parseFunctionBody(token, false, externalModifier != null);
|
| asyncState = savedAsyncModifier;
|
| @@ -1761,10 +1760,10 @@ class Parser {
|
| void checkFormals(bool isGetter, Token name, Token token) {
|
| if (optional("(", token)) {
|
| if (isGetter) {
|
| - reportRecoverableErrorCode(token, fasta.codeGetterWithFormals);
|
| + reportRecoverableError(token, fasta.codeGetterWithFormals);
|
| }
|
| } else if (!isGetter) {
|
| - reportRecoverableErrorCodeWithToken(name, fasta.codeNoFormals);
|
| + reportRecoverableError(name, fasta.codeNoFormals.bind(name));
|
| }
|
| }
|
|
|
| @@ -1889,7 +1888,7 @@ class Parser {
|
| }
|
| if (!optional('(', token)) {
|
| if (optional(';', token)) {
|
| - reportRecoverableErrorCode(token, fasta.codeExpectedOpenParens);
|
| + reportRecoverableError(token, fasta.codeExpectedOpenParens);
|
| }
|
| token = expect("(", token);
|
| }
|
| @@ -1916,11 +1915,9 @@ class Parser {
|
| } else {
|
| if (varFinalOrConst != null) {
|
| if (optional("const", varFinalOrConst)) {
|
| - reportRecoverableErrorCode(
|
| - name, fasta.codeConstFieldWithoutInitializer);
|
| + reportRecoverableError(name, fasta.codeConstFieldWithoutInitializer);
|
| } else if (isTopLevel && optional("final", varFinalOrConst)) {
|
| - reportRecoverableErrorCode(
|
| - name, fasta.codeFinalFieldWithoutInitializer);
|
| + reportRecoverableError(name, fasta.codeFinalFieldWithoutInitializer);
|
| }
|
| }
|
| listener.handleNoFieldInitializer(token);
|
| @@ -1980,9 +1977,9 @@ class Parser {
|
| if (identical(token.kind, STRING_TOKEN)) {
|
| return parseLiteralString(token);
|
| } else {
|
| - reportRecoverableErrorCodeWithToken(token, fasta.codeExpectedString);
|
| + reportRecoverableError(token, fasta.codeExpectedString.bind(token));
|
| return parseRecoverExpression(
|
| - token, fasta.codeExpectedString.format(uri, token.charOffset, token));
|
| + token, fasta.codeExpectedString.bind(token)(uri, token.charOffset));
|
| }
|
| }
|
|
|
| @@ -2056,8 +2053,8 @@ class Parser {
|
| currentOrder = order;
|
| if (optional("var", token)) {
|
| if (!isVarAllowed && parameterKind == null) {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| }
|
| switch (typeContinuation ?? TypeContinuation.Required) {
|
| case TypeContinuation.NormalFormalParameter:
|
| @@ -2081,27 +2078,27 @@ class Parser {
|
| }
|
| } else if (optional("final", token)) {
|
| if (!isVarAllowed && parameterKind == null) {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| }
|
| typeContinuation ??= TypeContinuation.Optional;
|
| } else if (optional("const", token)) {
|
| if (!isVarAllowed) {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| }
|
| typeContinuation ??= TypeContinuation.Optional;
|
| } else if (optional("static", token)) {
|
| if (parameterKind != null) {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| } else if (memberKind == MemberKind.NonStaticMethod) {
|
| memberKind = MemberKind.StaticMethod;
|
| } else if (memberKind == MemberKind.NonStaticField) {
|
| memberKind = MemberKind.StaticField;
|
| } else {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| token = token.next;
|
| continue;
|
| }
|
| @@ -2111,8 +2108,8 @@ class Parser {
|
| case MemberKind.StaticMethod:
|
| case MemberKind.TopLevelField:
|
| case MemberKind.TopLevelMethod:
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| token = token.next;
|
| continue;
|
|
|
| @@ -2128,8 +2125,8 @@ class Parser {
|
| break;
|
|
|
| default:
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| token = token.next;
|
| continue;
|
| }
|
| @@ -2137,8 +2134,8 @@ class Parser {
|
| token = parseModifier(token);
|
| count++;
|
| } else {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| token = token.next;
|
| }
|
| } else {
|
| @@ -2158,8 +2155,8 @@ class Parser {
|
|
|
| Token skipClassBody(Token token) {
|
| if (!optional('{', token)) {
|
| - return reportUnrecoverableErrorCodeWithToken(
|
| - token, fasta.codeExpectedClassBodyToSkip)
|
| + return reportUnrecoverableError(
|
| + token, fasta.codeExpectedClassBodyToSkip.bind(token))
|
| .next;
|
| }
|
| BeginToken beginGroupToken = token;
|
| @@ -2174,8 +2171,8 @@ class Parser {
|
| Token begin = token;
|
| listener.beginClassBody(token);
|
| if (!optional('{', token)) {
|
| - token = reportUnrecoverableErrorCodeWithToken(
|
| - token, fasta.codeExpectedClassBody)
|
| + token = reportUnrecoverableError(
|
| + token, fasta.codeExpectedClassBody.bind(token))
|
| .next;
|
| }
|
| token = token.next;
|
| @@ -2213,16 +2210,16 @@ class Parser {
|
|
|
| Link<Token> identifiers = findMemberName(token);
|
| if (identifiers.isEmpty) {
|
| - return reportUnrecoverableErrorCodeWithToken(
|
| - start, fasta.codeExpectedDeclaration)
|
| + return reportUnrecoverableError(
|
| + start, fasta.codeExpectedDeclaration.bind(token))
|
| .next;
|
| }
|
| Token afterName = identifiers.head;
|
| identifiers = identifiers.tail;
|
|
|
| if (identifiers.isEmpty) {
|
| - return reportUnrecoverableErrorCodeWithToken(
|
| - start, fasta.codeExpectedDeclaration)
|
| + return reportUnrecoverableError(
|
| + start, fasta.codeExpectedDeclaration.bind(start))
|
| .next;
|
| }
|
| Token name = identifiers.head;
|
| @@ -2306,8 +2303,8 @@ class Parser {
|
| for (; !tokens.isEmpty; tokens = tokens.tail) {
|
| Token token = tokens.head;
|
| if (optional("abstract", token)) {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| continue;
|
| }
|
| int order = modifierOrder(token);
|
| @@ -2315,12 +2312,12 @@ class Parser {
|
| if (order > currentOrder) {
|
| currentOrder = order;
|
| if (optional("var", token)) {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| } else if (optional("const", token)) {
|
| if (getOrSet != null) {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| continue;
|
| }
|
| } else if (optional("external", token)) {
|
| @@ -2331,14 +2328,14 @@ class Parser {
|
| if (staticModifier != null ||
|
| getOrSet == null ||
|
| optional("get", getOrSet)) {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| continue;
|
| }
|
| }
|
| } else {
|
| - reportRecoverableErrorCodeWithToken(
|
| - token, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + token, fasta.codeExtraneousModifier.bind(token));
|
| continue;
|
| }
|
| } else {
|
| @@ -2362,8 +2359,8 @@ class Parser {
|
| if (optional('operator', name)) {
|
| token = parseOperatorName(name);
|
| if (staticModifier != null) {
|
| - reportRecoverableErrorCodeWithToken(
|
| - staticModifier, fasta.codeExtraneousModifier);
|
| + reportRecoverableError(
|
| + staticModifier, fasta.codeExtraneousModifier.bind(staticModifier));
|
| }
|
| } else {
|
| token = parseIdentifier(name, IdentifierContext.methodDeclaration);
|
| @@ -2389,7 +2386,7 @@ class Parser {
|
| Token asyncToken = token;
|
| token = parseAsyncModifier(token);
|
| if (getOrSet != null && !inPlainSync && optional("set", getOrSet)) {
|
| - reportRecoverableErrorCode(asyncToken, fasta.codeSetterNotSync);
|
| + reportRecoverableError(asyncToken, fasta.codeSetterNotSync);
|
| }
|
| if (optional('=', token)) {
|
| token = parseRedirectingFactoryBody(token);
|
| @@ -2423,7 +2420,7 @@ class Parser {
|
| Token asyncToken = token;
|
| token = parseAsyncModifier(token);
|
| if (!inPlainSync) {
|
| - reportRecoverableErrorCode(asyncToken, fasta.codeFactoryNotSync);
|
| + reportRecoverableError(asyncToken, fasta.codeFactoryNotSync);
|
| }
|
| if (optional('=', token)) {
|
| token = parseRedirectingFactoryBody(token);
|
| @@ -2543,7 +2540,7 @@ class Parser {
|
| String value = token.stringValue;
|
| if (identical(value, ';')) {
|
| if (!allowAbstract) {
|
| - reportRecoverableErrorCode(token, fasta.codeExpectedBody);
|
| + reportRecoverableError(token, fasta.codeExpectedBody);
|
| }
|
| listener.handleNoFunctionBody(token);
|
| } else {
|
| @@ -2552,7 +2549,7 @@ class Parser {
|
| expectSemicolon(token);
|
| listener.handleFunctionBodySkipped(token, true);
|
| } else if (identical(value, '=')) {
|
| - reportRecoverableErrorCode(token, fasta.codeExpectedBody);
|
| + reportRecoverableError(token, fasta.codeExpectedBody);
|
| token = parseExpression(token.next);
|
| expectSemicolon(token);
|
| listener.handleFunctionBodySkipped(token, true);
|
| @@ -2567,7 +2564,7 @@ class Parser {
|
| Token parseFunctionBody(Token token, bool isExpression, bool allowAbstract) {
|
| if (optional(';', token)) {
|
| if (!allowAbstract) {
|
| - reportRecoverableErrorCode(token, fasta.codeExpectedBody);
|
| + reportRecoverableError(token, fasta.codeExpectedBody);
|
| }
|
| listener.handleEmptyFunctionBody(token);
|
| return token;
|
| @@ -2584,7 +2581,7 @@ class Parser {
|
| } else if (optional('=', token)) {
|
| Token begin = token;
|
| // Recover from a bad factory method.
|
| - reportRecoverableErrorCode(token, fasta.codeExpectedBody);
|
| + reportRecoverableError(token, fasta.codeExpectedBody);
|
| token = parseExpression(token.next);
|
| if (!isExpression) {
|
| expectSemicolon(token);
|
| @@ -2597,8 +2594,8 @@ class Parser {
|
| Token begin = token;
|
| int statementCount = 0;
|
| if (!optional('{', token)) {
|
| - token = reportUnrecoverableErrorCodeWithToken(
|
| - token, fasta.codeExpectedFunctionBody)
|
| + token = reportUnrecoverableError(
|
| + token, fasta.codeExpectedFunctionBody.bind(token))
|
| .next;
|
| listener.handleInvalidFunctionBody(token);
|
| return token;
|
| @@ -2657,14 +2654,14 @@ class Parser {
|
| star = token;
|
| token = token.next;
|
| } else {
|
| - reportRecoverableErrorCode(async, fasta.codeInvalidSyncModifier);
|
| + reportRecoverableError(async, fasta.codeInvalidSyncModifier);
|
| }
|
| }
|
| listener.handleAsyncModifier(async, star);
|
| if (inGenerator && optional('=>', token)) {
|
| - reportRecoverableErrorCode(token, fasta.codeGeneratorReturnsValue);
|
| + reportRecoverableError(token, fasta.codeGeneratorReturnsValue);
|
| } else if (!inPlainSync && optional(';', token)) {
|
| - reportRecoverableErrorCode(token, fasta.codeAbstractNotSync);
|
| + reportRecoverableError(token, fasta.codeAbstractNotSync);
|
| }
|
| return token;
|
| }
|
| @@ -2675,7 +2672,7 @@ class Parser {
|
| // This happens for degenerate programs, for example, a lot of nested
|
| // if-statements. The language test deep_nesting2_negative_test, for
|
| // example, provokes this.
|
| - return reportUnrecoverableErrorCode(token, fasta.codeStackOverflow).next;
|
| + return reportUnrecoverableError(token, fasta.codeStackOverflow).next;
|
| }
|
| Token result = parseStatementX(token);
|
| statementDepth--;
|
| @@ -2696,7 +2693,7 @@ class Parser {
|
| return parseIfStatement(token);
|
| } else if (identical(value, 'await') && optional('for', token.next)) {
|
| if (!inAsync) {
|
| - reportRecoverableErrorCode(token, fasta.codeAwaitForNotAsync);
|
| + reportRecoverableError(token, fasta.codeAwaitForNotAsync);
|
| }
|
| return parseForStatement(token, token.next);
|
| } else if (identical(value, 'for')) {
|
| @@ -2734,7 +2731,7 @@ class Parser {
|
| return parseYieldStatement(token);
|
|
|
| case AsyncModifier.Async:
|
| - reportRecoverableErrorCode(token, fasta.codeYieldNotGenerator);
|
| + reportRecoverableError(token, fasta.codeYieldNotGenerator);
|
| return parseYieldStatement(token);
|
| }
|
| throw "Internal error: Unknown asyncState: '$asyncState'.";
|
| @@ -2774,7 +2771,7 @@ class Parser {
|
| } else {
|
| token = parseExpression(token);
|
| if (inGenerator) {
|
| - reportRecoverableErrorCode(begin.next, fasta.codeGeneratorReturnsValue);
|
| + reportRecoverableError(begin.next, fasta.codeGeneratorReturnsValue);
|
| }
|
| listener.endReturnStatement(true, begin, token);
|
| }
|
| @@ -2896,7 +2893,7 @@ class Parser {
|
| // This happens in degenerate programs, for example, with a lot of nested
|
| // list literals. This is provoked by, for examaple, the language test
|
| // deep_nesting1_negative_test.
|
| - return reportUnrecoverableErrorCode(token, fasta.codeStackOverflow).next;
|
| + return reportUnrecoverableError(token, fasta.codeStackOverflow).next;
|
| }
|
| listener.beginExpression(token);
|
| Token result = optional('throw', token)
|
| @@ -3037,7 +3034,7 @@ class Parser {
|
| }
|
| } else if (identical(value, '+')) {
|
| // Dart no longer allows prefix-plus.
|
| - reportRecoverableErrorCode(token, fasta.codeUnsupportedPrefixPlus);
|
| + reportRecoverableError(token, fasta.codeUnsupportedPrefixPlus);
|
| return parseUnaryExpression(token.next, allowCascades);
|
| } else if ((identical(value, '!')) ||
|
| (identical(value, '-')) ||
|
| @@ -3140,8 +3137,8 @@ class Parser {
|
| }
|
|
|
| Token expressionExpected(Token token) {
|
| - token = reportUnrecoverableErrorCodeWithToken(
|
| - token, fasta.codeExpectedExpression)
|
| + token = reportUnrecoverableError(
|
| + token, fasta.codeExpectedExpression.bind(token))
|
| .next;
|
| listener.handleInvalidExpression(token);
|
| return token;
|
| @@ -3206,7 +3203,7 @@ class Parser {
|
| token = parseArguments(token);
|
| listener.endSend(beginToken, token);
|
| } else if (optional("?.", token)) {
|
| - reportRecoverableErrorCode(token, fasta.codeSuperNullAware);
|
| + reportRecoverableError(token, fasta.codeSuperNullAware);
|
| }
|
| return token;
|
| }
|
| @@ -3682,7 +3679,7 @@ class Parser {
|
| return parseForInRest(awaitToken, forKeyword, leftParenthesis, token);
|
| } else {
|
| if (awaitToken != null) {
|
| - reportRecoverableErrorCode(awaitToken, fasta.codeInvalidAwaitFor);
|
| + reportRecoverableError(awaitToken, fasta.codeInvalidAwaitFor);
|
| }
|
| return parseForRest(forKeyword, leftParenthesis, token);
|
| }
|
| @@ -3788,7 +3785,7 @@ class Parser {
|
| listener.beginAwaitExpression(awaitToken);
|
| token = expect('await', token);
|
| if (!inAsync) {
|
| - reportRecoverableErrorCode(awaitToken, fasta.codeAwaitNotAsync);
|
| + reportRecoverableError(awaitToken, fasta.codeAwaitNotAsync);
|
| }
|
| token = parsePrecedenceExpression(token, POSTFIX_PRECEDENCE, allowCascades);
|
| listener.endAwaitExpression(awaitToken, token);
|
| @@ -3847,15 +3844,15 @@ class Parser {
|
| if (!optional("(", openParens)) {
|
| // Handled below by parseFormalParameters.
|
| } else if (!exceptionName.isIdentifier) {
|
| - reportRecoverableErrorCode(exceptionName, fasta.codeCatchSyntax);
|
| + reportRecoverableError(exceptionName, fasta.codeCatchSyntax);
|
| } else if (optional(")", commaOrCloseParens)) {
|
| // OK: `catch (identifier)`.
|
| } else if (!optional(",", commaOrCloseParens)) {
|
| - reportRecoverableErrorCode(exceptionName, fasta.codeCatchSyntax);
|
| + reportRecoverableError(exceptionName, fasta.codeCatchSyntax);
|
| } else if (!traceName.isIdentifier) {
|
| - reportRecoverableErrorCode(exceptionName, fasta.codeCatchSyntax);
|
| + reportRecoverableError(exceptionName, fasta.codeCatchSyntax);
|
| } else if (!optional(")", closeParens)) {
|
| - reportRecoverableErrorCode(exceptionName, fasta.codeCatchSyntax);
|
| + reportRecoverableError(exceptionName, fasta.codeCatchSyntax);
|
| }
|
| token = parseFormalParameters(token.next, MemberKind.Catch);
|
| }
|
| @@ -3873,7 +3870,7 @@ class Parser {
|
| listener.handleFinallyBlock(finallyKeyword);
|
| } else {
|
| if (catchCount == 0) {
|
| - reportRecoverableErrorCode(tryKeyword, fasta.codeOnlyTry);
|
| + reportRecoverableError(tryKeyword, fasta.codeOnlyTry);
|
| }
|
| }
|
| listener.endTryStatement(catchCount, tryKeyword, finallyKeyword);
|
| @@ -3954,8 +3951,8 @@ class Parser {
|
| } else {
|
| if (expressionCount == 0) {
|
| // TODO(ahe): This is probably easy to recover from.
|
| - reportUnrecoverableErrorCodeWithString(
|
| - token, fasta.codeExpectedButGot, "case");
|
| + reportUnrecoverableError(
|
| + token, fasta.codeExpectedButGot.bind("case"));
|
| }
|
| break;
|
| }
|
| @@ -4015,11 +4012,10 @@ class Parser {
|
| token = token.next;
|
| Token begin = token;
|
| token = parseExpression(token);
|
| - listener.handleExtraneousExpression(begin,
|
| - fasta.codeAssertExtraneousArgument.format(uri, token.charOffset));
|
| + listener.handleExtraneousExpression(
|
| + begin, fasta.codeAssertExtraneousArgument(uri, token.charOffset));
|
| }
|
| - reportRecoverableErrorCode(
|
| - firstExtra, fasta.codeAssertExtraneousArgument);
|
| + reportRecoverableError(firstExtra, fasta.codeAssertExtraneousArgument);
|
| }
|
| Token rightParenthesis = token;
|
| token = expect(')', token);
|
| @@ -4027,7 +4023,7 @@ class Parser {
|
| listener.endAssert(assertKeyword, kind, leftParenthesis, commaToken,
|
| rightParenthesis, token);
|
| if (kind == Assert.Expression) {
|
| - reportRecoverableErrorCode(assertKeyword, fasta.codeAssertAsExpression);
|
| + reportRecoverableError(assertKeyword, fasta.codeAssertAsExpression);
|
| }
|
| return token;
|
| }
|
| @@ -4057,102 +4053,66 @@ class Parser {
|
|
|
| /// Don't call this method. Should only be used as a last resort when there
|
| /// is no feasible way to recover from a parser error.
|
| - Token reportUnrecoverableError(Token token, FastaMessage format()) {
|
| + Token reportUnrecoverableError(
|
| + Token token, FastaMessage Function(Uri, int) bind) {
|
| Token next;
|
| if (token is ErrorToken) {
|
| next = reportErrorToken(token, false);
|
| } else {
|
| - next = listener.handleUnrecoverableError(token, format());
|
| + next =
|
| + listener.handleUnrecoverableError(token, bind(uri, token.charOffset));
|
| }
|
| return next ?? skipToEof(token);
|
| }
|
|
|
| - void reportRecoverableError(Token token, FastaMessage format()) {
|
| + void reportRecoverableError(
|
| + Token token, FastaMessage Function(Uri, int) bind) {
|
| if (token is ErrorToken) {
|
| reportErrorToken(token, true);
|
| } else {
|
| - listener.handleRecoverableError(token, format());
|
| + listener.handleRecoverableError(token, bind(uri, token.charOffset));
|
| }
|
| }
|
|
|
| Token reportErrorToken(ErrorToken token, bool isRecoverable) {
|
| FastaCode code = token.errorCode;
|
| - FastaMessage message;
|
| + BoundFastaMessage bind;
|
| if (code == fasta.codeAsciiControlCharacter) {
|
| - message = fasta.codeAsciiControlCharacter
|
| - .format(uri, token.charOffset, token.character);
|
| + bind = fasta.codeAsciiControlCharacter.bind(token.character);
|
| } else if (code == fasta.codeNonAsciiWhitespace) {
|
| - message = fasta.codeNonAsciiWhitespace
|
| - .format(uri, token.charOffset, token.character);
|
| + bind = fasta.codeNonAsciiWhitespace.bind(token.character);
|
| } else if (code == fasta.codeEncoding) {
|
| - message = fasta.codeEncoding.format(uri, token.charOffset);
|
| + bind = fasta.codeEncoding;
|
| } else if (code == fasta.codeNonAsciiIdentifier) {
|
| - message = fasta.codeNonAsciiIdentifier.format(uri, token.charOffset,
|
| - new String.fromCharCodes([token.character]), token.character);
|
| + bind = fasta.codeNonAsciiIdentifier
|
| + .bind(new String.fromCharCodes([token.character]), token.character);
|
| } else if (code == fasta.codeUnterminatedString) {
|
| - message = fasta.codeUnterminatedString
|
| - .format(uri, token.charOffset, token.start);
|
| + bind = fasta.codeUnterminatedString.bind(token.start);
|
| } else if (code == fasta.codeUnmatchedToken) {
|
| Token begin = token.begin;
|
| - message = fasta.codeUnmatchedToken
|
| - .format(uri, token.charOffset, closeBraceFor(begin.lexeme), begin);
|
| + bind = fasta.codeUnmatchedToken.bind(closeBraceFor(begin.lexeme), begin);
|
| } else if (code == fasta.codeUnspecified) {
|
| - message = fasta.codeUnspecified
|
| - .format(uri, token.charOffset, token.assertionMessage);
|
| + bind = fasta.codeUnspecified.bind(token.assertionMessage);
|
| } else {
|
| - message = code.format(uri, token.charOffset);
|
| + bind = code as BoundFastaCode;
|
| }
|
| if (isRecoverable) {
|
| - listener.handleRecoverableError(token, message);
|
| + listener.handleRecoverableError(token, bind(uri, token.charOffset));
|
| return null;
|
| } else {
|
| - Token next = listener.handleUnrecoverableError(token, message);
|
| + Token next =
|
| + listener.handleUnrecoverableError(token, bind(uri, token.charOffset));
|
| return next ?? skipToEof(token);
|
| }
|
| }
|
|
|
| Token reportUnmatchedToken(BeginToken token) {
|
| - return reportUnrecoverableError(
|
| - token,
|
| - () => fasta.codeUnmatchedToken
|
| - .format(uri, token.charOffset, closeBraceFor(token.lexeme), token));
|
| - }
|
| -
|
| - Token reportUnexpectedToken(Token token) {
|
| return reportUnrecoverableError(token,
|
| - () => fasta.codeUnexpectedToken.format(uri, token.charOffset, token));
|
| - }
|
| -
|
| - void reportRecoverableErrorCode(Token token, FastaCode<NoArgument> code) {
|
| - reportRecoverableError(token, () => code.format(uri, token.charOffset));
|
| - }
|
| -
|
| - Token reportUnrecoverableErrorCode(Token token, FastaCode<NoArgument> code) {
|
| - return reportUnrecoverableError(
|
| - token, () => code.format(uri, token.charOffset));
|
| + fasta.codeUnmatchedToken.bind(closeBraceFor(token.lexeme), token));
|
| }
|
|
|
| - void reportRecoverableErrorCodeWithToken(
|
| - Token token, FastaCode<TokenArgument> code) {
|
| - reportRecoverableError(
|
| - token, () => code.format(uri, token.charOffset, token));
|
| - }
|
| -
|
| - Token reportUnrecoverableErrorCodeWithToken(
|
| - Token token, FastaCode<TokenArgument> code) {
|
| - return reportUnrecoverableError(
|
| - token, () => code.format(uri, token.charOffset, token));
|
| - }
|
| -
|
| - Token reportUnrecoverableErrorCodeWithString(
|
| - Token token, FastaCode<StringArgument> code, String string) {
|
| + Token reportUnexpectedToken(Token token) {
|
| return reportUnrecoverableError(
|
| - token, () => code.format(uri, token.charOffset, string));
|
| + token, fasta.codeUnexpectedToken.bind(token));
|
| }
|
| }
|
| -
|
| -typedef FastaMessage NoArgument(Uri uri, int charOffset);
|
| -
|
| -typedef FastaMessage TokenArgument(Uri uri, int charOffset, Token token);
|
| -
|
| -typedef FastaMessage StringArgument(Uri uri, int charOffset, String string);
|
|
|