From eb85d5294a45ffdc0a8012781aa64e50ecdbe5df Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Mon, 2 Jul 2018 17:39:50 +0300 Subject: [PATCH] [groovy] parse slashy literals as reference expressions (IDEA-194880) --- .../lang/parser/GroovyGeneratedParser.java | 7 +++--- .../plugins/groovy/lang/parser/groovy.bnf | 2 +- .../lang/parser/ExpressionsParsingTest.groovy | 2 ++ .../commandExpr/slashyInvoked.test | 25 +++++++++++++++++++ .../groovy/expressions/regex/regex4.test | 2 +- 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 plugins/groovy/testdata/parsing/groovy/expressions/commandExpr/slashyInvoked.test diff --git a/plugins/groovy/groovy-psi/gen/org/jetbrains/plugins/groovy/lang/parser/GroovyGeneratedParser.java b/plugins/groovy/groovy-psi/gen/org/jetbrains/plugins/groovy/lang/parser/GroovyGeneratedParser.java index e0fc371055d3..e4f00f7a2c72 100644 --- a/plugins/groovy/groovy-psi/gen/org/jetbrains/plugins/groovy/lang/parser/GroovyGeneratedParser.java +++ b/plugins/groovy/groovy-psi/gen/org/jetbrains/plugins/groovy/lang/parser/GroovyGeneratedParser.java @@ -7566,7 +7566,7 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser { // | 'this' // | 'super' // | code_reference_identifiers_soft &(reference_dot | '.&') - // | (STR_SQ | STR_DQ) &string_literal_as_reference + // | (STR_SQ | STR_DQ | regex_literal) &string_literal_as_reference public static boolean unqualified_reference_expression(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "unqualified_reference_expression")) return false; boolean r; @@ -7630,7 +7630,7 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser { return r; } - // (STR_SQ | STR_DQ) &string_literal_as_reference + // (STR_SQ | STR_DQ | regex_literal) &string_literal_as_reference private static boolean unqualified_reference_expression_4(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "unqualified_reference_expression_4")) return false; boolean r; @@ -7641,12 +7641,13 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser { return r; } - // STR_SQ | STR_DQ + // STR_SQ | STR_DQ | regex_literal private static boolean unqualified_reference_expression_4_0(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "unqualified_reference_expression_4_0")) return false; boolean r; r = consumeTokenSmart(b, STR_SQ); if (!r) r = consumeTokenSmart(b, STR_DQ); + if (!r) r = regex_literal(b, l + 1); return r; } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/parser/groovy.bnf b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/parser/groovy.bnf index a7b3910474d5..951580bf9ac8 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/parser/groovy.bnf +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/parser/groovy.bnf @@ -839,7 +839,7 @@ unqualified_reference_expression ::= IDENTIFIER soft_type_argument_list? | 'this' | 'super' | code_reference_identifiers_soft &(reference_dot | '.&') - | (STR_SQ | STR_DQ) &string_literal_as_reference + | (STR_SQ | STR_DQ | regex_literal) &string_literal_as_reference { elementType = reference_expression } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/ExpressionsParsingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/ExpressionsParsingTest.groovy index 626f804c4e21..009d46fa13c3 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/ExpressionsParsingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/ExpressionsParsingTest.groovy @@ -636,6 +636,8 @@ class ExpressionsParsingTest extends GroovyParsingTestCase { void testcommandExpr$literalInvoked() { doTest() } + void testcommandExpr$slashyInvoked() { doTest() } + void testcommandExpr$safeIndex() { doTest() } void testcommandExpr$safeIndexEmpty() { doTest() } diff --git a/plugins/groovy/testdata/parsing/groovy/expressions/commandExpr/slashyInvoked.test b/plugins/groovy/testdata/parsing/groovy/expressions/commandExpr/slashyInvoked.test new file mode 100644 index 000000000000..7ed24a3c2d65 --- /dev/null +++ b/plugins/groovy/testdata/parsing/groovy/expressions/commandExpr/slashyInvoked.test @@ -0,0 +1,25 @@ +/a/ b +$/a/$ b +----- +Groovy script + Call expression + Reference expression + GroovyASTPsiElementImpl(SLASHY_LITERAL) + PsiElement(regex begin)('/') + PsiElement(regex content)('a') + PsiElement(regex end)('/') + PsiWhiteSpace(' ') + Command arguments + Reference expression + PsiElement(identifier)('b') + PsiElement(new line)('\n') + Call expression + Reference expression + GroovyASTPsiElementImpl(DOLLAR_SLASHY_LITERAL) + PsiElement($/ regex begin)('$/') + PsiElement($/ regex content)('a') + PsiElement($/ regex end)('/$') + PsiWhiteSpace(' ') + Command arguments + Reference expression + PsiElement(identifier)('b') \ No newline at end of file diff --git a/plugins/groovy/testdata/parsing/groovy/expressions/regex/regex4.test b/plugins/groovy/testdata/parsing/groovy/expressions/regex/regex4.test index 6bd7bac50ee6..71b136b87fb8 100644 --- a/plugins/groovy/testdata/parsing/groovy/expressions/regex/regex4.test +++ b/plugins/groovy/testdata/parsing/groovy/expressions/regex/regex4.test @@ -3,7 +3,7 @@ ----- Groovy script Call expression - Literal + Reference expression GroovyASTPsiElementImpl(SLASHY_LITERAL) PsiElement(regex begin)('/') PsiElement(regex content)('asd\n')