Fix recovery for 'for' expression

This commit is contained in:
Nikolay Krasko
2014-06-20 15:28:42 +04:00
parent 2571797411
commit f36f1796d6
24 changed files with 458 additions and 42 deletions
@@ -9,6 +9,6 @@ fun test(nothing: Nothing?) {
}
fun sum(<!UNUSED_PARAMETER!>a<!> : IntArray) : Int {
for (n
<!SYNTAX!>return<!> <!ITERATOR_MISSING!>"?"<!><!SYNTAX!><!>
<!SYNTAX!><!>}
for (n
<!SYNTAX!>return<!><!SYNTAX!><!> "?"
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
+4 -12
View File
@@ -658,17 +658,9 @@ JetFile: ForWithMultiDecl.kt
PsiErrorElement:Expecting 'in'
<empty list>
PsiWhiteSpace(' ')
LOOP_RANGE
FUNCTION_LITERAL_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
BLOCK
<empty list>
PsiElement(RBRACE)('}')
PsiErrorElement:Expecting ')'
<empty list>
PsiWhiteSpace('\n')
BODY
PsiErrorElement:Expecting an expression
<empty list>
BLOCK
PsiElement(LBRACE)('{')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1,7 @@
fun test(): Int {
for () {
}
return 1
}
@@ -0,0 +1,41 @@
JetFile: ForEmptyParentheses.kt
PACKAGE_DIRECTIVE
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('Int')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FOR
PsiElement(for)('for')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
PsiErrorElement:Expecting a variable name
<empty list>
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BODY
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n ')
RETURN
PsiElement(return)('return')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1,5 @@
fun test(): Int {
for ()
return 1
}
@@ -0,0 +1,36 @@
JetFile: ForEmptyWithoutBody.kt
PACKAGE_DIRECTIVE
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('Int')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FOR
PsiElement(for)('for')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
PsiErrorElement:Expecting a variable name
<empty list>
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n ')
BODY
RETURN
PsiElement(return)('return')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1,5 @@
fun test() {
while (true) {
for ()
}
}
@@ -0,0 +1,41 @@
JetFile: ForNoBodyBeforeRBrace.kt
PACKAGE_DIRECTIVE
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
WHILE
PsiElement(while)('while')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
CONDITION
BOOLEAN_CONSTANT
PsiElement(true)('true')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BODY
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FOR
PsiElement(for)('for')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
PsiErrorElement:Expecting a variable name
<empty list>
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
BODY
PsiErrorElement:Expecting an expression
<empty list>
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1 @@
fun test() = for (
@@ -0,0 +1,26 @@
JetFile: ForWithOnlyOneLParInEOF.kt
PACKAGE_DIRECTIVE
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
FOR
PsiElement(for)('for')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiErrorElement:Expecting a variable name
<empty list>
PsiErrorElement:Expecting 'in'
<empty list>
PsiErrorElement:Expecting ')'
<empty list>
BODY
<empty list>
@@ -0,0 +1 @@
fun test() = for ()
@@ -0,0 +1,23 @@
JetFile: ForWithoutBodyInEOF.kt
PACKAGE_DIRECTIVE
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
FOR
PsiElement(for)('for')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
PsiErrorElement:Expecting a variable name
<empty list>
PsiElement(RPAR)(')')
BODY
PsiErrorElement:Expecting an expression
<empty list>
@@ -0,0 +1,5 @@
fun test(): Int {
for
return 1
}
@@ -0,0 +1,33 @@
JetFile: ForWithoutLPar.kt
PACKAGE_DIRECTIVE
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('Int')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FOR
PsiElement(for)('for')
PsiErrorElement:Expecting '(' to open a loop range
<empty list>
PsiWhiteSpace('\n\n ')
BODY
RETURN
PsiElement(return)('return')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1 @@
fun test() = for
@@ -0,0 +1,20 @@
JetFile: ForWithoutLParInEOF.kt
PACKAGE_DIRECTIVE
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
FOR
PsiElement(for)('for')
PsiErrorElement:Expecting '(' to open a loop range
<empty list>
BODY
PsiErrorElement:Expecting an expression
<empty list>
@@ -0,0 +1,4 @@
fun test() {
for (in some()) {
}
}
@@ -0,0 +1,39 @@
JetFile: ForWithoutParamButWithRange.kt
PACKAGE_DIRECTIVE
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FOR
PsiElement(for)('for')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiErrorElement:Expecting a variable name
<empty list>
PsiElement(in)('in')
PsiWhiteSpace(' ')
LOOP_RANGE
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('some')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BODY
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1,5 @@
fun test() {
for (some)
bar()
}
@@ -0,0 +1,33 @@
JetFile: ForWithoutRange.kt
PACKAGE_DIRECTIVE
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FOR
PsiElement(for)('for')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('some')
PsiErrorElement:Expecting 'in'
<empty list>
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n ')
BODY
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1,5 @@
fun test() {
for ((i, j))
foo()
}
@@ -0,0 +1,40 @@
JetFile: WithWithoutInAndMultideclaration.kt
PACKAGE_DIRECTIVE
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FOR
PsiElement(for)('for')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
MULTI_VARIABLE_DECLARATION
PsiElement(LPAR)('(')
MULTI_VARIABLE_DECLARATION_ENTRY
PsiElement(IDENTIFIER)('i')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
MULTI_VARIABLE_DECLARATION_ENTRY
PsiElement(IDENTIFIER)('j')
PsiElement(RPAR)(')')
PsiErrorElement:Expecting 'in'
<empty list>
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n ')
BODY
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')