[groovy] allow new line before elvis operand (IDEA-195296)

This commit is contained in:
Daniil Ovchinnikov
2018-07-09 22:24:35 +03:00
parent 9cb2079b18
commit ac231a6af6
4 changed files with 27 additions and 2 deletions
@@ -7291,11 +7291,22 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
return r;
}
// '?:' mb_nl
// mb_nl ('?:' mb_nl)
private static boolean elvis_expression_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "elvis_expression_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = mb_nl(b, l + 1);
r = r && elvis_expression_0_1(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
// '?:' mb_nl
private static boolean elvis_expression_0_1(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "elvis_expression_0_1")) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeTokenSmart(b, T_ELVIS);
r = r && mb_nl(b, l + 1);
exit_section_(b, m, null, r);
@@ -1076,7 +1076,7 @@ private conditionals ::= ternary_expression | elvis_expression
ternary_expression ::= expression (ternary_tail_pin | ternary_tail)
private ternary_tail_pin ::= '?' mb_nl !'[' expression mb_nl ':' mb_nl conditionals { pin = 3 consumeTokenMethod = 'consumeTokenFast' }
private ternary_tail ::= '?' mb_nl expression mb_nl ':' mb_nl conditionals { pin = 5 consumeTokenMethod = 'consumeTokenFast' }
elvis_expression ::= expression '?:' mb_nl expression
elvis_expression ::= expression mb_nl ('?:' mb_nl) expression
{
rightAssociative = true
}
@@ -81,6 +81,8 @@ class ExpressionsParsingTest extends GroovyParsingTestCase {
void testconditional$elvis2() throws Throwable { doTest() }
void testconditional$elvisNlBeforeOperator() { doTest() }
void testconditional$ternaryQuestionOnly() { doTest() }
void testconditional$ternaryWithoutElse() { doTest() }
@@ -0,0 +1,12 @@
a
?: b
-----
Groovy script
Elvis expression
Reference expression
PsiElement(identifier)('a')
PsiElement(new line)('\n')
PsiElement(?:)('?:')
PsiWhiteSpace(' ')
Reference expression
PsiElement(identifier)('b')