You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/04/10 21:39:47 UTC

[groovy] branch master updated: GROOVY-10024: Dollar slashy /$ string ending in backslash "breaks" the parser (closes #1552)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 2b341fd  GROOVY-10024: Dollar slashy /$ string ending in backslash "breaks" the parser (closes #1552)
2b341fd is described below

commit 2b341fd1fe83405b12a637bcddcc88595e3ec24f
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Apr 10 11:59:32 2021 +1000

    GROOVY-10024: Dollar slashy /$ string ending in backslash "breaks" the parser (closes #1552)
---
 src/antlr/GroovyLexer.g4          |  6 +++---
 src/spec/doc/core-syntax.adoc     | 11 ++++++-----
 src/test/groovy/StringTest.groovy |  6 ++++++
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/antlr/GroovyLexer.g4 b/src/antlr/GroovyLexer.g4
index 4b7a295..9b34f4d 100644
--- a/src/antlr/GroovyLexer.g4
+++ b/src/antlr/GroovyLexer.g4
@@ -369,9 +369,9 @@ fragment SlashyStringCharacter
     |   ~[/$\u0000]
     ;
 
-// character in the collar slashy string. e.g. $/a/$
+// character in the dollar slashy string. e.g. $/a/$
 fragment DollarSlashyStringCharacter
-    :   SlashEscape | DollarSlashEscape | DollarDollarEscape
+    :   DollarSlashEscape | DollarDollarEscape
     |   Slash { _input.LA(1) != '$' }?
     |   Dollar { !isFollowedByJavaLetterInGString(_input) }?
     |   ~[/$\u0000]
@@ -793,7 +793,7 @@ DollarSlashyGStringQuotationMarkEnd
 
 fragment
 DollarSlashEscape
-    :   '$/$'
+    :   '$/'
     ;
 
 fragment
diff --git a/src/spec/doc/core-syntax.adoc b/src/spec/doc/core-syntax.adoc
index 44e18f3..9c06f26 100644
--- a/src/spec/doc/core-syntax.adoc
+++ b/src/spec/doc/core-syntax.adoc
@@ -594,13 +594,14 @@ You can instead use a special trick, `/ends with slash ${'\'}/`. But best just a
 
 === Dollar slashy string
 
-Dollar slashy strings are multiline GStrings delimited with an opening `$/` and and a closing `/$`.
+Dollar slashy strings are multiline GStrings delimited with an opening `$/` and a closing `/$`.
 The escaping character is the dollar sign, and it can escape another dollar, or a forward slash.
-But both dollar and forward slashes don't need to be escaped, except to escape the dollar of a string
-subsequence that would start like a GString placeholder sequence, or if you need to escape a sequence
-that would start like a closing dollar slashy string delimiter.
+Escaping for the dollar and forward slash characters is only needed where conflicts arise with
+the special use of those characters. The characters `$foo` would normally indicate a GString
+placeholder, so those four characters can be entered into a dollar slashy string by escaping the dollar, i.e. `$$foo`.
+Similarly, you will need to escape a dollar slashy closing delimiter if you want it to appear in your string.
 
-Here's an example:
+Here are a few examples:
 
 [source,groovy]
 ----
diff --git a/src/test/groovy/StringTest.groovy b/src/test/groovy/StringTest.groovy
index 6f348d8..8e6a472 100644
--- a/src/test/groovy/StringTest.groovy
+++ b/src/test/groovy/StringTest.groovy
@@ -241,6 +241,12 @@ foo
 
         text = $/$$$$$//$
         assert text == '$$/'
+
+        //GROOVY-10024
+        def s1 = $/abc\\/$
+        def s2 = $/def\/$
+        def s3 = $/ghi/$
+        assert s1 == 'abc\\\\' && s2 == 'def\\' && s3 == 'ghi'
     }
 
     void testSplit() {