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 2015/06/25 12:54:59 UTC

[1/2] incubator-groovy git commit: GROOVY-7377: Interpolated variable followed by asterisk in slashy-string causes compiler error

Repository: incubator-groovy
Updated Branches:
  refs/heads/master e45962bac -> fe7fb466a


GROOVY-7377: Interpolated variable followed by asterisk in slashy-string causes compiler error


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/72abd754
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/72abd754
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/72abd754

Branch: refs/heads/master
Commit: 72abd7549cd760159645f2f0af9ffed321fee014
Parents: e45962b
Author: Paul King <pa...@asert.com.au>
Authored: Thu Jun 11 20:26:00 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Thu Jun 25 10:52:30 2015 +1000

----------------------------------------------------------------------
 src/main/org/codehaus/groovy/antlr/groovy.g | 37 ++++++++++--------------
 src/test/groovy/GStringTest.groovy          | 10 +++++++
 2 files changed, 26 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/72abd754/src/main/org/codehaus/groovy/antlr/groovy.g
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/antlr/groovy.g b/src/main/org/codehaus/groovy/antlr/groovy.g
index bcd7d93..0dc106c 100644
--- a/src/main/org/codehaus/groovy/antlr/groovy.g
+++ b/src/main/org/codehaus/groovy/antlr/groovy.g
@@ -3478,12 +3478,11 @@ options {
     }
 
     protected boolean atValidDollarEscape() throws CharStreamException {
-        // '$' (('*')? ('{' | LETTER)) =>
+        // '$' (('{' | LETTER) =>
         int k = 1;
         char lc = LA(k++);
         if (lc != '$')  return false;
         lc = LA(k++);
-        if (lc == '*')  lc = LA(k++);
         return (lc == '{' || (lc != '$' && Character.isJavaIdentifierStart(lc)));
     }
 
@@ -3755,7 +3754,7 @@ options {
 // multiple-line comments
 ML_COMMENT
 options {
-    paraphrase="a comment";
+    paraphrase="a multi-line comment";
 }
     :   "/*"
         (   /*  '\r' '\n' can be matched in one alternative or by matching
@@ -3854,7 +3853,8 @@ options {
     paraphrase="a multiline regular expression literal";
 }
         {int tt=0;}
-    :   {allowRegexpLiteral()}?
+    :   ( '/' ~('*'|'=') ) =>
+        {allowRegexpLiteral()}?
         '/'!
         {++suppressNewline;}
         //Do this, but require it to be non-trivial:  REGEXP_CTOR_END[true]
@@ -3874,8 +3874,8 @@ options {
         )
         {$setType(tt);}
 
-    |   DIV                 {$setType(DIV);}
-    |   DIV_ASSIGN          {$setType(DIV_ASSIGN);}
+    |   ( '/' ~('*'|'=') ) => DIV {$setType(DIV);}
+    |   DIV_ASSIGN {$setType(DIV_ASSIGN);}
     ;
 
 DOLLAR_REGEXP_LITERAL
@@ -3980,14 +3980,11 @@ options {
     paraphrase="a multiline regular expression character";
 }
     :
-        (
-            ~('*'|'/'|'$'|'\\'|'\n'|'\r'|'\uffff')
-        |   { LA(2)!='/' && LA(2)!='\n' && LA(2)!='\r' }? '\\' // backslash only escapes '/' and EOL
-        |   '\\' '/'                   { $setText('/'); }
-        |   STRING_NL[true]
-        |!  '\\' ONE_NL[false]
-        )
-        ('*')*      // stars handled specially to avoid ambig. on /**/
+        ~('/'|'$'|'\\'|'\n'|'\r'|'\uffff')
+    |   { LA(2)!='/' && LA(2)!='\n' && LA(2)!='\r' }? '\\' // backslash only escapes '/' and EOL
+    |   '\\' '/'                   { $setText('/'); }
+    |   STRING_NL[true]
+    |!  '\\' ONE_NL[false]
     ;
 
 protected
@@ -3996,13 +3993,11 @@ options {
     paraphrase="a multiline dollar escaping regular expression character";
 }
     :
-        (
-            ~('$' | '\\' | '/' | '\n' | '\r' | '\uffff')
-        |   { LA(2)!='\n' && LA(2)!='\r' }? '\\'               // backslash only escapes EOL
-        |   ('/' ~'$') => '/'                                  // allow a slash if not followed by a $
-        |   STRING_NL[true]
-        |!  '\\' ONE_NL[false]
-        )
+        ~('$' | '\\' | '/' | '\n' | '\r' | '\uffff')
+    |   { LA(2)!='\n' && LA(2)!='\r' }? '\\'               // backslash only escapes EOL
+    |   ('/' ~'$') => '/'                                  // allow a slash if not followed by a $
+    |   STRING_NL[true]
+    |!  '\\' ONE_NL[false]
     ;
 
 // escape sequence -- note that this is protected; it can only be called

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/72abd754/src/test/groovy/GStringTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/GStringTest.groovy b/src/test/groovy/GStringTest.groovy
index 24eba7b..10d2488 100644
--- a/src/test/groovy/GStringTest.groovy
+++ b/src/test/groovy/GStringTest.groovy
@@ -570,4 +570,14 @@ class GStringTest extends GroovyTestCase {
         assert gstring.bytes == string.bytes
         assert gstring.getBytes('UTF-8') ==  string.getBytes('UTF-8')
     }
+
+    /**
+     * GROOVY-7377: Interpolated variable followed by asterisk in slashy-string causes compiler error
+     */
+    void testSlashyStringWithInterpolatedVariableFollowedByAsterisk() {
+        assert Eval.me('''def foo='bar'; /$foo*baz/''') == 'bar*baz'
+        assert Eval.me('''def foo='bar'; /${foo}*baz/''') == 'bar*baz'
+        assert Eval.me('''def foo='bar'; /$foo\u002abaz/''') == 'bar*baz'
+        assert Eval.me('''def foo='bar'; /${foo}\u002abaz/''') == 'bar*baz'
+    }
 }


[2/2] incubator-groovy git commit: GROOVY-7377: Interpolated variable followed by asterisk in slashy-string causes compiler error (tweak)

Posted by pa...@apache.org.
GROOVY-7377: Interpolated variable followed by asterisk in slashy-string causes compiler error (tweak)


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/fe7fb466
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/fe7fb466
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/fe7fb466

Branch: refs/heads/master
Commit: fe7fb466aa73ed368d0c853486315577df710a9c
Parents: 72abd75
Author: paulk <pa...@asert.com.au>
Authored: Thu Jun 25 20:39:24 2015 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Thu Jun 25 20:39:24 2015 +1000

----------------------------------------------------------------------
 src/main/org/codehaus/groovy/antlr/groovy.g | 51 +++++++++++++-----------
 1 file changed, 28 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/fe7fb466/src/main/org/codehaus/groovy/antlr/groovy.g
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/antlr/groovy.g b/src/main/org/codehaus/groovy/antlr/groovy.g
index 0dc106c..3512399 100644
--- a/src/main/org/codehaus/groovy/antlr/groovy.g
+++ b/src/main/org/codehaus/groovy/antlr/groovy.g
@@ -3490,6 +3490,10 @@ options {
         return LA(1) == '$' && LA(2) == '$';
     }
 
+    protected boolean atMultiCommentStart() throws CharStreamException {
+        return LA(1) == '/' && LA(2) == '*';
+    }
+
     protected boolean atDollarSlashEscape() throws CharStreamException {
         return LA(1) == '$' && LA(2) == '/';
     }
@@ -3756,7 +3760,7 @@ ML_COMMENT
 options {
     paraphrase="a multi-line comment";
 }
-    :   "/*"
+    :   { atMultiCommentStart() }? "/*"
         (   /*  '\r' '\n' can be matched in one alternative or by matching
                 '\r' in one iteration and '\n' in another. I am trying to
                 handle any flavor of newline that comes in, but the language
@@ -3853,29 +3857,30 @@ options {
     paraphrase="a multiline regular expression literal";
 }
         {int tt=0;}
-    :   ( '/' ~('*'|'=') ) =>
-        {allowRegexpLiteral()}?
-        '/'!
-        {++suppressNewline;}
-        //Do this, but require it to be non-trivial:  REGEXP_CTOR_END[true]
-        // There must be at least one symbol or $ escape, lest the regexp collapse to '//'.
-        // (This should be simpler, but I don't know how to do it w/o ANTLR warnings vs. '//' comments.)
-        (
-            REGEXP_SYMBOL
-            tt=REGEXP_CTOR_END[true]
-        |   {!atValidDollarEscape()}? '$'
-            tt=REGEXP_CTOR_END[true]
-        |   '$'!
-            {
-                // Yes, it's a regexp constructor, and we've got a value part.
-                tt = STRING_CTOR_START;
-                stringCtorState = SCS_VAL + SCS_RE_TYPE;
-            }
-        )
-        {$setType(tt);}
+    :   { !atMultiCommentStart() }?
+        (   {allowRegexpLiteral()}?
+            '/'!
+            {++suppressNewline;}
+            //Do this, but require it to be non-trivial:  REGEXP_CTOR_END[true]
+            // There must be at least one symbol or $ escape, lest the regexp collapse to '//'.
+            // (This should be simpler, but I don't know how to do it w/o ANTLR warnings vs. '//' comments.)
+            (
+                REGEXP_SYMBOL
+                tt=REGEXP_CTOR_END[true]
+            |   {!atValidDollarEscape()}? '$'
+                tt=REGEXP_CTOR_END[true]
+            |   '$'!
+                {
+                    // Yes, it's a regexp constructor, and we've got a value part.
+                    tt = STRING_CTOR_START;
+                    stringCtorState = SCS_VAL + SCS_RE_TYPE;
+                }
+            )
+            {$setType(tt);}
 
-    |   ( '/' ~('*'|'=') ) => DIV {$setType(DIV);}
-    |   DIV_ASSIGN {$setType(DIV_ASSIGN);}
+        |   ( '/' ~'=' ) => DIV {$setType(DIV);}
+        |   DIV_ASSIGN {$setType(DIV_ASSIGN);}
+        )
     ;
 
 DOLLAR_REGEXP_LITERAL