Fixed the parser bug when a no-else if was followed by a semicolon and no newline

This commit is contained in:
Andrey Breslav
2011-04-11 17:23:43 +04:00
parent 54050f9de5
commit 69ef281d47
5 changed files with 100 additions and 3 deletions
@@ -1279,7 +1279,9 @@ public class JetExpressionParsing extends AbstractJetParsing {
if (!at(ELSE_KEYWORD) && !at(SEMICOLON)) { if (!at(ELSE_KEYWORD) && !at(SEMICOLON)) {
parseExpression(); parseExpression();
} }
consumeIf(SEMICOLON); if (at(SEMICOLON) && lookahead(1) == ELSE_KEYWORD) {
advance(); // SEMICOLON
}
thenBranch.done(THEN); thenBranch.done(THEN);
if (at(ELSE_KEYWORD)) { if (at(ELSE_KEYWORD)) {
+1
View File
@@ -0,0 +1 @@
fun foo(a: Int): Int { var x = a; var y = x++; if (y+1 != x) return -1; return x; }
+94
View File
@@ -0,0 +1,94 @@
JetFile: SemicolonAfterIf.jet
NAMESPACE
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('foo')
TYPE_PARAMETER_LIST
<empty 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)('}')