Fix recovery in enum initializers

This commit is contained in:
Nikolay Krasko
2014-04-29 17:27:48 +04:00
parent ad0e6dadf4
commit 5839fda22f
5 changed files with 324 additions and 15 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1732,22 +1732,24 @@ public class JetExpressionParsing extends AbstractJetParsing {
PsiBuilder.Marker list = mark();
myBuilder.disableNewlines();
expect(LPAR, "Expecting an argument list", EXPRESSION_FOLLOW);
if (!at(RPAR)) {
while (true) {
while (at(COMMA)) errorAndAdvance("Expecting an argument");
parseValueArgument();
if (!at(COMMA)) break;
advance(); // COMMA
if (at(RPAR)) {
error("Expecting an argument");
break;
if (expect(LPAR, "Expecting an argument list", EXPRESSION_FOLLOW)) {
if (!at(RPAR)) {
while (true) {
while (at(COMMA)) errorAndAdvance("Expecting an argument");
parseValueArgument();
if (!at(COMMA)) break;
advance(); // COMMA
if (at(RPAR)) {
error("Expecting an argument");
break;
}
}
}
expect(RPAR, "Expecting ')'", EXPRESSION_FOLLOW);
}
expect(RPAR, "Expecting ')'", EXPRESSION_FOLLOW);
myBuilder.restoreNewlinesState();
list.done(VALUE_ARGUMENT_LIST);
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ public class JetParsing extends AbstractJetParsing {
private static final TokenSet PARAMETER_NAME_RECOVERY_SET = TokenSet.create(COLON, EQ, COMMA, RPAR);
private static final TokenSet PACKAGE_NAME_RECOVERY_SET = TokenSet.create(DOT, EOL_OR_SEMICOLON);
private static final TokenSet IMPORT_RECOVERY_SET = TokenSet.create(AS_KEYWORD, DOT, EOL_OR_SEMICOLON);
/*package*/ static final TokenSet TYPE_REF_FIRST = TokenSet.create(LBRACKET, IDENTIFIER, FUN_KEYWORD, LPAR, CAPITALIZED_THIS_KEYWORD, HASH);
/*package*/ static final TokenSet TYPE_REF_FIRST = TokenSet.create(LBRACKET, IDENTIFIER, LPAR, CAPITALIZED_THIS_KEYWORD, HASH);
private static final TokenSet RECEIVER_TYPE_TERMINATORS = TokenSet.create(DOT, SAFE_ACCESS);
private static final TokenSet VALUE_PARAMETER_FIRST =
TokenSet.orSet(TokenSet.create(IDENTIFIER, LBRACKET, VAL_KEYWORD, VAR_KEYWORD), MODIFIER_KEYWORDS);
@@ -788,7 +788,8 @@ public class JetParsing extends AbstractJetParsing {
type = DELEGATOR_SUPER_CALL;
}
else {
errorWithRecovery("Expecting constructor call (this(...)) or supertype initializer", TokenSet.create(LBRACE, COMMA));
errorWithRecovery("Expecting constructor call (this(...)) or supertype initializer",
TokenSet.orSet(TOPLEVEL_OBJECT_FIRST, TokenSet.create(RBRACE, LBRACE, COMMA, SEMICOLON)));
initializer.drop();
return;
}