From 69ef281d47cbaf8e4a894288bbcad152d6b625ae Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 11 Apr 2011 17:23:43 +0400 Subject: [PATCH] Fixed the parser bug when a no-else if was followed by a semicolon and no newline --- .../lang/parsing/JetExpressionParsing.java | 4 +- idea/testData/psi/ControlStructures.txt | 2 +- idea/testData/psi/SemicolonAfterIf.jet | 1 + idea/testData/psi/SemicolonAfterIf.txt | 94 +++++++++++++++++++ .../psi/examples/AnonymousObjects.txt | 2 +- 5 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 idea/testData/psi/SemicolonAfterIf.jet create mode 100644 idea/testData/psi/SemicolonAfterIf.txt diff --git a/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java b/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java index 4669b212ea0..9d91b53f8d2 100644 --- a/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java +++ b/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java @@ -1279,7 +1279,9 @@ public class JetExpressionParsing extends AbstractJetParsing { if (!at(ELSE_KEYWORD) && !at(SEMICOLON)) { parseExpression(); } - consumeIf(SEMICOLON); + if (at(SEMICOLON) && lookahead(1) == ELSE_KEYWORD) { + advance(); // SEMICOLON + } thenBranch.done(THEN); if (at(ELSE_KEYWORD)) { diff --git a/idea/testData/psi/ControlStructures.txt b/idea/testData/psi/ControlStructures.txt index 45e96659ef3..644a425edd0 100644 --- a/idea/testData/psi/ControlStructures.txt +++ b/idea/testData/psi/ControlStructures.txt @@ -880,7 +880,7 @@ JetFile: ControlStructures.jet THEN REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('b') - PsiElement(SEMICOLON)(';') + PsiElement(SEMICOLON)(';') PsiWhiteSpace('\n\n ') IF PsiElement(if)('if') diff --git a/idea/testData/psi/SemicolonAfterIf.jet b/idea/testData/psi/SemicolonAfterIf.jet new file mode 100644 index 00000000000..b28a527b471 --- /dev/null +++ b/idea/testData/psi/SemicolonAfterIf.jet @@ -0,0 +1 @@ +fun foo(a: Int): Int { var x = a; var y = x++; if (y+1 != x) return -1; return x; } diff --git a/idea/testData/psi/SemicolonAfterIf.txt b/idea/testData/psi/SemicolonAfterIf.txt new file mode 100644 index 00000000000..54ec05a25de --- /dev/null +++ b/idea/testData/psi/SemicolonAfterIf.txt @@ -0,0 +1,94 @@ +JetFile: SemicolonAfterIf.jet + NAMESPACE + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + TYPE_PARAMETER_LIST + + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace(' ') + PROPERTY + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace(' ') + PROPERTY + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('y') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + POSTFIX_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + OPERATION_REFERENCE + PsiElement(PLUSPLUS)('++') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace(' ') + IF + PsiElement(if)('if') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + CONDITION + BINARY_EXPRESSION + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('y') + OPERATION_REFERENCE + PsiElement(PLUS)('+') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(EXCLEQ)('!=') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + THEN + RETURN + PsiElement(return)('return') + PsiWhiteSpace(' ') + PREFIX_EXPRESSION + OPERATION_REFERENCE + PsiElement(MINUS)('-') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace(' ') + RETURN + PsiElement(return)('return') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace(' ') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/idea/testData/psi/examples/AnonymousObjects.txt b/idea/testData/psi/examples/AnonymousObjects.txt index 7c371957290..415b88a11a9 100644 --- a/idea/testData/psi/examples/AnonymousObjects.txt +++ b/idea/testData/psi/examples/AnonymousObjects.txt @@ -115,7 +115,7 @@ JetFile: AnonymousObjects.jet REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('TOO_MANY_CLICKS') PsiElement(RPAR)(')') - PsiElement(SEMICOLON)(';') + PsiElement(SEMICOLON)(';') PsiWhiteSpace('\n ') PsiElement(RBRACE)('}') PsiWhiteSpace('\n')