Don't parse condition if there's no ( for if

This commit is contained in:
Nikolay Krasko
2014-06-23 20:20:24 +04:00
parent e06154c204
commit 2571797411
14 changed files with 286 additions and 7 deletions
@@ -1548,13 +1548,14 @@ public class JetExpressionParsing extends AbstractJetParsing {
*/
private void parseCondition() {
myBuilder.disableNewlines();
expect(LPAR, "Expecting a condition in parentheses '(...)'");
PsiBuilder.Marker condition = mark();
parseExpression();
condition.done(CONDITION);
if (expect(LPAR, "Expecting a condition in parentheses '(...)'", EXPRESSION_FIRST)) {
PsiBuilder.Marker condition = mark();
parseExpression();
condition.done(CONDITION);
expect(RPAR, "Expecting ')");
}
expect(RPAR, "Expecting ')");
myBuilder.restoreNewlinesState();
}
@@ -0,0 +1,7 @@
fun test(): Boolean {
do {
} while()
return true
}
@@ -0,0 +1,43 @@
JetFile: DoWhileWithEmptyCondition.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)('Boolean')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
DO_WHILE
PsiElement(do)('do')
PsiWhiteSpace(' ')
BODY
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ')
PsiElement(while)('while')
PsiElement(LPAR)('(')
CONDITION
PsiErrorElement:Expecting an expression
<empty list>
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n ')
RETURN
PsiElement(return)('return')
PsiWhiteSpace(' ')
BOOLEAN_CONSTANT
PsiElement(true)('true')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1,7 @@
fun test(): Boolean {
do {
} while
return true
}
@@ -0,0 +1,40 @@
JetFile: DoWhileWithoutLPar.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)('Boolean')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
DO_WHILE
PsiElement(do)('do')
PsiWhiteSpace(' ')
BODY
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ')
PsiElement(while)('while')
PsiErrorElement:Expecting a condition in parentheses '(...)'
<empty list>
PsiWhiteSpace('\n\n ')
RETURN
PsiElement(return)('return')
PsiWhiteSpace(' ')
BOOLEAN_CONSTANT
PsiElement(true)('true')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1,5 @@
fun test() {
if ()
return true
}
@@ -0,0 +1,31 @@
JetFile: IfWithEmptyCondition.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 ')
IF
PsiElement(if)('if')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
CONDITION
PsiErrorElement:Expecting an expression
<empty list>
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n ')
THEN
RETURN
PsiElement(return)('return')
PsiWhiteSpace(' ')
BOOLEAN_CONSTANT
PsiElement(true)('true')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1,6 @@
fun test() {
if
if (other) {
}
}
@@ -0,0 +1,36 @@
JetFile: IfWithoutLPar.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 ')
IF
PsiElement(if)('if')
PsiErrorElement:Expecting a condition in parentheses '(...)'
<empty list>
PsiWhiteSpace('\n\n ')
THEN
IF
PsiElement(if)('if')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
CONDITION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('other')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
THEN
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1,5 @@
fun test() {
while ()
return
}
@@ -0,0 +1,28 @@
JetFile: WhileWithEmptyCondition.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
PsiErrorElement:Expecting an expression
<empty list>
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n ')
BODY
RETURN
PsiElement(return)('return')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1,5 @@
fun test(): Boolean {
while
return true
}
@@ -0,0 +1,33 @@
JetFile: WhileWithoutLPar.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)('Boolean')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
WHILE
PsiElement(while)('while')
PsiErrorElement:Expecting a condition in parentheses '(...)'
<empty list>
PsiWhiteSpace('\n\n ')
BODY
RETURN
PsiElement(return)('return')
PsiWhiteSpace(' ')
BOOLEAN_CONSTANT
PsiElement(true)('true')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -882,19 +882,41 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest {
}
public void testAllFilesPresentInRecovery() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/psi/recovery"), Pattern.compile("^(.*)\\.kts?$"), true);
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage",
new File("compiler/testData/psi/recovery"), Pattern.compile("^(.*)\\.kts?$"),
true);
}
@TestMetadata("DoWhileWithEmptyCondition.kt")
public void testDoWhileWithEmptyCondition() throws Exception {
doParsingTest("compiler/testData/psi/recovery/DoWhileWithEmptyCondition.kt");
}
@TestMetadata("DoWhileWithoutLPar.kt")
public void testDoWhileWithoutLPar() throws Exception {
doParsingTest("compiler/testData/psi/recovery/DoWhileWithoutLPar.kt");
}
@TestMetadata("EnumEntryInitList.kt")
public void testEnumEntryInitList() throws Exception {
doParsingTest("compiler/testData/psi/recovery/EnumEntryInitList.kt");
}
@TestMetadata("ForRecovery.kt")
public void testForRecovery() throws Exception {
doParsingTest("compiler/testData/psi/recovery/ForRecovery.kt");
}
@TestMetadata("IfWithEmptyCondition.kt")
public void testIfWithEmptyCondition() throws Exception {
doParsingTest("compiler/testData/psi/recovery/IfWithEmptyCondition.kt");
}
@TestMetadata("IfWithoutLPar.kt")
public void testIfWithoutLPar() throws Exception {
doParsingTest("compiler/testData/psi/recovery/IfWithoutLPar.kt");
}
@TestMetadata("ImportRecovery.kt")
public void testImportRecovery() throws Exception {
doParsingTest("compiler/testData/psi/recovery/ImportRecovery.kt");
@@ -950,6 +972,16 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest {
doParsingTest("compiler/testData/psi/recovery/ValueParameterNoTypeRecovery.kt");
}
@TestMetadata("WhileWithEmptyCondition.kt")
public void testWhileWithEmptyCondition() throws Exception {
doParsingTest("compiler/testData/psi/recovery/WhileWithEmptyCondition.kt");
}
@TestMetadata("WhileWithoutLPar.kt")
public void testWhileWithoutLPar() throws Exception {
doParsingTest("compiler/testData/psi/recovery/WhileWithoutLPar.kt");
}
}
@TestMetadata("compiler/testData/psi/script")