IDEA-93954 Groovy parser: \n is allowed before colon in ternary operator

This commit is contained in:
Max Medvedev
2012-11-01 10:50:51 +04:00
parent 7a06688fec
commit 107cbe5293
2 changed files with 295 additions and 40 deletions
@@ -46,6 +46,10 @@ public class ConditionalExpression implements GroovyElementTypes {
if (!AssignmentExpression.parse(builder, parser)) {
builder.error(GroovyBundle.message("expression.expected"));
}
if (ParserUtils.lookAhead(builder, mNLS, mCOLON)) {
ParserUtils.getToken(builder, mNLS);
}
if (ParserUtils.getToken(builder, mCOLON, GroovyBundle.message("colon.expected"))) {
ParserUtils.getToken(builder, mNLS);
parse(builder, parser);
@@ -25,208 +25,401 @@ public class ExpressionsParsingTest extends GroovyParsingTestCase {
}
public void testarguments$carg1() throws Throwable { doTest(); }
public void testarguments$carg2() throws Throwable { doTest(); }
public void testarguments$carg3() throws Throwable { doTest(); }
public void testarguments$cargs1() throws Throwable { doTest(); }
public void testarguments$cargs2() throws Throwable { doTest(); }
public void testarguments$cargs3() throws Throwable { doTest(); }
public void testarithmetic$add1() throws Throwable { doTest(); }
public void testarithmetic$add2() throws Throwable { doTest(); }
public void testarithmetic$addbug1() throws Throwable { doTest(); }
public void testarithmetic$arif1() throws Throwable { doTest(); }
public void testarithmetic$mul1() throws Throwable { doTest(); }
public void testarithmetic$mul2() throws Throwable { doTest(); }
public void testarithmetic$mul3() throws Throwable { doTest(); }
public void testarithmetic$post1() throws Throwable { doTest(); }
public void testarithmetic$sh1() throws Throwable { doTest(); }
public void testarithmetic$shift5() throws Throwable { doTest(); }
public void testarithmetic$shift6() throws Throwable { doTest(); }
public void testarithmetic$un1() throws Throwable { doTest(); }
public void testass1() throws Throwable { doTest(); }
public void testass2() throws Throwable { doTest(); }
public void testass3() throws Throwable { doTest(); }
public void testclosures$appended() throws Throwable { doTest(); }
public void testclosures$closparam1() throws Throwable { doTest(); }
public void testclosures$closparam2() throws Throwable { doTest(); }
public void testclosures$closparam3() throws Throwable { doTest(); }
public void testclosures$closparam4() throws Throwable { doTest(); }
public void testclosures$closparam5() throws Throwable { doTest(); }
public void testclosures$closparam6() throws Throwable { doTest(); }
public void testclosures$final_error() throws Throwable { doTest(); }
public void testclosures$param6() throws Throwable { doTest(); }
public void testclosures$param7() throws Throwable { doTest(); }
public void testconditional$con1() throws Throwable { doTest(); }
public void testconditional$con2() throws Throwable { doTest(); }
public void testconditional$elvis1() throws Throwable { doTest(); }
public void testconditional$elvis2() throws Throwable { doTest(); }
public void testerrors$err_final() throws Throwable { doTest(); }
public void testgstring$daniel_sun() throws Throwable { doTest(); }
public void testgstring$gravy16532() throws Throwable { doTest("gstring/gravy-1653-2.test"); }
public void testgstring$grvy1653() throws Throwable { doTest("gstring/grvy-1653.test"); }
public void testgstring$gstr3() throws Throwable { doTest(); }
public void testgstring$standTrooper() throws Throwable { doTest(); }
public void testgstring$str1() throws Throwable { doTest(); }
public void testgstring$str2() throws Throwable { doTest(); }
public void testgstring$str3() throws Throwable { doTest(); }
public void testgstring$str4() throws Throwable { doTest(); }
public void testgstring$str5() throws Throwable { doTest(); }
public void testgstring$str6() throws Throwable { doTest(); }
public void testgstring$str7() throws Throwable { doTest(); }
public void testgstring$str8() throws Throwable { doTest(); }
public void testgstring$str_error1() throws Throwable { doTest(); }
public void testgstring$str_error2() throws Throwable { doTest(); }
public void testgstring$str_error3() throws Throwable { doTest(); }
public void testgstring$str_error4() throws Throwable { doTest(); }
public void testgstring$str_error5() throws Throwable { doTest(); }
public void testgstring$str_error6() throws Throwable { doTest(); }
public void testgstring$str_error7() throws Throwable { doTest(); }
public void testgstring$str_error8() throws Throwable { doTest(); }
public void testgstring$triple$triple1() throws Throwable { doTest(); }
public void testgstring$triple$triple2() throws Throwable { doTest(); }
public void testgstring$triple$triple3() throws Throwable { doTest(); }
public void testgstring$triple$quote_and_slash() throws Throwable { doTest(); }
public void testgstring$ugly_lexer() throws Throwable { doTest(); }
public void testmapLiteral() throws Throwable { doTest(); }
public void testnew$arr_decl() throws Throwable { doTest(); }
// public void testnew$new1() throws Throwable { doTest(); }
public void testanonymous$anonymous() throws Throwable { doTest(); }
public void testnumbers() throws Throwable { doTest(); }
public void testparenthed$exprInParenth() throws Throwable { doTest(); }
public void testparenthed$paren1() throws Throwable { doTest(); }
public void testparenthed$paren2() throws Throwable { doTest(); }
public void testparenthed$paren3() throws Throwable { doTest(); }
public void testparenthed$paren4() throws Throwable { doTest(); }
public void testparenthed$paren5() throws Throwable { doTest(); }
public void testparenthed$paren6() throws Throwable { doTest(); }
public void testpath$method$ass4() throws Throwable { doTest(); }
public void testpath$method$clazz1() throws Throwable { doTest(); }
public void testpath$method$clazz2() throws Throwable { doTest(); }
public void testpath$method$clos1() throws Throwable { doTest(); }
public void testpath$method$clos2() throws Throwable { doTest(); }
public void testpath$method$clos3() throws Throwable { doTest(); }
public void testpath$method$clos4() throws Throwable { doTest(); }
public void testpath$method$ind1() throws Throwable { doTest(); }
public void testpath$method$ind2() throws Throwable { doTest(); }
public void testpath$method$ind3() throws Throwable { doTest(); }
public void testpath$method$method1() throws Throwable { doTest(); }
public void testpath$method$method10() throws Throwable { doTest(); }
public void testpath$method$method11() throws Throwable { doTest(); }
public void testpath$method$method12() throws Throwable { doTest(); }
public void testpath$method$method13() throws Throwable { doTest(); }
public void testpath$method$method2() throws Throwable { doTest(); }
public void testpath$method$method3() throws Throwable { doTest(); }
public void testpath$method$method4() throws Throwable { doTest(); }
public void testpath$method$method5() throws Throwable { doTest(); }
public void testpath$method$method6() throws Throwable { doTest(); }
public void testpath$method$method7() throws Throwable { doTest(); }
public void testpath$method$method8() throws Throwable { doTest(); }
public void testpath$method$method9() throws Throwable { doTest(); }
public void testpath$path1() throws Throwable { doTest(); }
public void testpath$path13() throws Throwable { doTest(); }
public void testpath$path14() throws Throwable { doTest(); }
public void testpath$path2() throws Throwable { doTest(); }
public void testpath$path3() throws Throwable { doTest(); }
public void testpath$path4() throws Throwable { doTest(); }
public void testpath$path5() throws Throwable { doTest(); }
public void testpath$path6() throws Throwable { doTest(); }
public void testpath$path7() throws Throwable { doTest(); }
public void testpath$path8() throws Throwable { doTest(); }
public void testpath$path9() throws Throwable { doTest(); }
public void testpath$path10() throws Throwable {doTest(); }
public void testpath$regexp() {doTest()}
public void testpath$typeVsExpr() {doTest();}
public void testpath$path10() throws Throwable { doTest(); }
public void testpath$regexp() { doTest() }
public void testpath$typeVsExpr() { doTest(); }
public void testreferences$ref1() throws Throwable { doTest(); }
public void testreferences$ref2() throws Throwable { doTest(); }
public void testreferences$ref3() throws Throwable { doTest(); }
public void testreferences$ref4() throws Throwable { doTest(); }
public void testreferences$ref5() throws Throwable { doTest(); }
public void testreferences$ref6() throws Throwable { doTest(); }
public void testreferences$ref7() throws Throwable { doTest(); }
public void testregex$chen() throws Throwable { doTest(); }
public void testregex$GRVY1509err() throws Throwable { doTest("regex/GRVY-1509err.test"); }
public void testregex$GRVY1509norm() throws Throwable { doTest("regex/GRVY-1509norm.test"); }
public void testregex$GRVY1509test() throws Throwable { doTest("regex/GRVY-1509test.test"); }
public void testregex$regex1() throws Throwable { doTest(); }
public void testregex$regex10() throws Throwable { doTest(); }
public void testregex$regex11() throws Throwable { doTest(); }
public void testregex$regex12() throws Throwable { doTest(); }
public void testregex$regex13() throws Throwable { doTest(); }
public void testregex$regex14() throws Throwable { doTest(); }
public void testregex$regex15() throws Throwable { doTest(); }
public void testregex$regex16() throws Throwable { doTest(); }
public void testregex$regex17() throws Throwable { doTest(); }
public void testregex$regex18() throws Throwable { doTest(); }
public void testregex$regex19() throws Throwable { doTest(); }
public void testregex$regex2() throws Throwable { doTest(); }
public void testregex$regex20() throws Throwable { doTest(); }
public void testregex$regex21() throws Throwable { doTest(); }
public void testregex$regex22() throws Throwable { doTest(); }
public void testregex$regex23() throws Throwable { doTest(); }
public void testregex$regex3() throws Throwable { doTest(); }
public void testregex$regex33() throws Throwable { doTest(); }
public void testregex$regex4() throws Throwable { doTest(); }
public void testregex$regex5() throws Throwable { doTest(); }
public void testregex$regex6() throws Throwable { doTest(); }
public void testregex$regex7() throws Throwable { doTest(); }
public void testregex$regex8() throws Throwable { doTest(); }
public void testregex$regex9() throws Throwable { doTest(); }
public void testregex$regex_begin() throws Throwable { doTest(); }
public void testregex$regex_begin2() throws Throwable { doTest(); }
public void testregex$multiLineSlashy() throws Throwable { doTest(); }
public void testregex$dollarSlashy() throws Throwable { doTest(); }
public void testregex$dollarSlashy2() throws Throwable { doTest(); }
public void testregex$dollarSlashy3() throws Throwable { doTest(); }
public void testregex$dollarSlashy4() throws Throwable { doTest(); }
public void testregex$dollarSlashy5() throws Throwable { doTest(); }
public void testregex$dollarSlashy6() throws Throwable { doTest(); }
public void testregex$dollarSlashy7() throws Throwable { doTest(); }
public void testregex$dollarSlashy8() throws Throwable { doTest(); }
public void testregex$dollarSlashy9() throws Throwable { doTest(); }
public void testregex$dollarSlashyCode() throws Throwable { doTest(); }
public void testregex$dollarSlashyCodeUnfinished() throws Throwable { doTest(); }
public void testregex$dollarSlashyEof() throws Throwable { doTest(); }
public void testregex$dollarSlashyRegex() throws Throwable { doTest(); }
public void testregex$dollarSlashyRegexFinishedTwice() throws Throwable { doTest(); }
public void testregex$dollarSlashyRegexUnfinished() throws Throwable { doTest(); }
public void testregex$dollarSlashyUnfinished() throws Throwable { doTest(); }
public void testregex$dollarSlashyWindowsPaths() throws Throwable { doTest(); }
public void testregex$dollarSlashyXml() throws Throwable { doTest(); }
public void testregex$dollarSlashyDouble() throws Throwable { doTest(); }
public void testregex$dollarSlashyTriple() throws Throwable { doTest(); }
public void testrelational$eq1() throws Throwable { doTest(); }
public void testrelational$inst0() throws Throwable { doTest(); }
public void testrelational$inst1() throws Throwable { doTest(); }
public void testrelational$inst2() throws Throwable { doTest(); }
public void testrelational$rel1() throws Throwable { doTest(); }
public void testspecial$grvy1173() throws Throwable { doTest(); }
public void testspecial$list1() throws Throwable { doTest(); }
public void testspecial$list2() throws Throwable { doTest(); }
public void testspecial$list3() throws Throwable { doTest(); }
public void testspecial$map1() throws Throwable { doTest(); }
public void testspecial$map2() throws Throwable { doTest(); }
public void testspecial$map3() throws Throwable { doTest(); }
public void testspecial$map4() throws Throwable { doTest(); }
public void testspecial$map5() throws Throwable { doTest(); }
public void testspecial$map6() throws Throwable { doTest(); }
public void testspecial$map7() throws Throwable { doTest(); }
public void testspecial$map8() throws Throwable { doTest(); }
public void testspecial$paren13() throws Throwable { doTest(); }
public void testtypecast$castToObject() throws Throwable { doTest(); }
public void testtypecast$una1() throws Throwable { doTest(); }
public void testtypecast$una2() throws Throwable { doTest(); }
public void testtypecast$una3() throws Throwable { doTest(); }
public void testtypecast$una4() throws Throwable { doTest(); }
public void testtypecast$una5() throws Throwable { doTest(); }
public void testtypecast$una6() throws Throwable { doTest(); }
public void testtypecast$elvis() throws Throwable { doTest(); }
public void testtypecast$conditional() throws Throwable { doTest(); }
public void testAtHang() throws Throwable { doTest(); }
public void testDollar() throws Throwable { doTest(); }
public void testNoArrowClosure() throws Throwable { doTest(); }
public void testNoArrowClosure2() throws Throwable { doTest(); }
public void testPropertyAccessError() throws Throwable {
@@ -251,10 +444,14 @@ public class ExpressionsParsingTest extends GroovyParsingTestCase {
PsiErrorElement:';' or new line expected
PsiElement(})('}')"""
}
public void testthis$qualifiedThis() throws Throwable {doTest();}
public void testsuper$qualifiedSuper() throws Throwable {doTest();}
public void testthis$this() throws Throwable {doTest();}
public void testsuper$super() throws Throwable {doTest();}
public void testthis$qualifiedThis() throws Throwable { doTest(); }
public void testsuper$qualifiedSuper() throws Throwable { doTest(); }
public void testthis$this() throws Throwable { doTest(); }
public void testsuper$super() throws Throwable { doTest(); }
public void testTripleEqual() throws Exception {
checkParsing "2===3", """Groovy script
@@ -267,41 +464,68 @@ public class ExpressionsParsingTest extends GroovyParsingTestCase {
"""
}
public void testcommandExpr$closureArg() {doTest()}
public void testcommandExpr$simple() {doTest()}
public void testcommandExpr$callArg1() {doTest()}
public void testcommandExpr$callArg2() {doTest()}
public void testcommandExpr$threeArgs1() {doTest()}
public void testcommandExpr$threeArgs2() {doTest()}
public void testcommandExpr$threeArgs3() {doTest()}
public void testcommandExpr$fourArgs() {doTest()}
public void testcommandExpr$fiveArgs() {doTest()}
public void testcommandExpr$multiArgs() {doTest()}
public void testcommandExpr$RHS() {doTest()}
public void testcommandExpr$oddArgCount() {doTest()}
public void testcommandExpr$indexAccess1() {doTest()}
public void testcommandExpr$indexAccess2() {doTest()}
public void testcommandExpr$indexAccess3() {doTest()}
public void testcommandExpr$closureArg2() {doTest()}
public void testcommandExpr$closureArg3() {doTest()}
public void testcommandExpr$not() {doTest()}
public void testcommandExpr$methodCall() {doTest()}
public void testcommandExpr$indexProperty() {doTest()}
public void testcommandExpr$closureArg() { doTest() }
public void testcommandExpr$instanceof() {doTest()}
public void testcommandExpr$instanceof2() {doTest()}
public void testcommandExpr$in() {doTest()}
public void testcommandExpr$as() {doTest()}
public void testcommandExpr$arrayAccess() {doTest()}
public void testcommandExpr$keywords() {doTest()}
public void testcommandExpr$literalInvoked() {doTest()}
public void testcommandExpr$simple() { doTest() }
public void testDiamond() {doTest()}
public void testcommandExpr$callArg1() { doTest() }
public void testcommandExpr$callArg2() { doTest() }
public void testcommandExpr$threeArgs1() { doTest() }
public void testcommandExpr$threeArgs2() { doTest() }
public void testcommandExpr$threeArgs3() { doTest() }
public void testcommandExpr$fourArgs() { doTest() }
public void testcommandExpr$fiveArgs() { doTest() }
public void testcommandExpr$multiArgs() { doTest() }
public void testcommandExpr$RHS() { doTest() }
public void testcommandExpr$oddArgCount() { doTest() }
public void testcommandExpr$indexAccess1() { doTest() }
public void testcommandExpr$indexAccess2() { doTest() }
public void testcommandExpr$indexAccess3() { doTest() }
public void testcommandExpr$closureArg2() { doTest() }
public void testcommandExpr$closureArg3() { doTest() }
public void testcommandExpr$not() { doTest() }
public void testcommandExpr$methodCall() { doTest() }
public void testcommandExpr$indexProperty() { doTest() }
public void testcommandExpr$instanceof() { doTest() }
public void testcommandExpr$instanceof2() { doTest() }
public void testcommandExpr$in() { doTest() }
public void testcommandExpr$as() { doTest() }
public void testcommandExpr$arrayAccess() { doTest() }
public void testcommandExpr$keywords() { doTest() }
public void testcommandExpr$literalInvoked() { doTest() }
public void testDiamond() { doTest() }
void testpath$stringMethodCall1() { doTest() }
void testpath$stringMethodCall2() { doTest() }
void testpath$stringMethodCall3() { doTest() }
void testpath$stringMethodCall1() {doTest()}
void testpath$stringMethodCall2() {doTest()}
void testpath$stringMethodCall3() {doTest()}
void testSpacesInStringAfterSlash() {
checkParsing '''
print 'abc \\ \ncde' ''', '''
@@ -316,7 +540,7 @@ Groovy script
PsiElement(string)(\'\'abc \\ \\ncde\'\')
PsiWhiteSpace(\' \')'''
}
void testDiamondInPathRefElement() {
checkParsing 'Map<String, String> map = new java.util.concurrent.ConcurrentHashMap<>()', '''
Groovy script
@@ -579,4 +803,31 @@ Groovy script
PsiElement(})('}')
PsiElement(new line)('\\n')'''
}
void testConditionalExpressionWithLineFeed() {
checkParsing('''\
print true ? abc
:cde
''', '''\
Groovy script
Call expression
Reference expression
PsiElement(identifier)('print')
PsiWhiteSpace(' ')
Command arguments
Conditional expression
Literal
PsiElement(true)('true')
PsiWhiteSpace(' ')
PsiElement(?)('?')
PsiWhiteSpace(' ')
Reference expression
PsiElement(identifier)('abc')
PsiElement(new line)('\\n')
PsiElement(:)(':')
Reference expression
PsiElement(identifier)('cde')
PsiElement(new line)('\\n')
''')
}
}