groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [1/2] incubator-groovy git commit: GROOVY-7377: Interpolated variable followed by asterisk in slashy-string causes compiler error
Date Thu, 25 Jun 2015 11:19:50 GMT
Repository: incubator-groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 5a2ae99be -> 4ca482d76


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/2fdfc9c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/2fdfc9c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/2fdfc9c2

Branch: refs/heads/GROOVY_2_4_X
Commit: 2fdfc9c23c4669c682ed360ec3e6002b84ee902f
Parents: 5a2ae99
Author: Paul King <paulk@asert.com.au>
Authored: Thu Jun 11 20:26:00 2015 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Thu Jun 25 21:18:08 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/2fdfc9c2/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 d342440..ee62f03 100644
--- a/src/main/org/codehaus/groovy/antlr/groovy.g
+++ b/src/main/org/codehaus/groovy/antlr/groovy.g
@@ -3524,12 +3524,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)));
     }
 
@@ -3801,7 +3800,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
@@ -3900,7 +3899,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]
@@ -3920,8 +3920,8 @@ options {
         )
         {$setType(tt);}
 
-    |   DIV                 {$setType(DIV);}
-    |   DIV_ASSIGN          {$setType(DIV_ASSIGN);}
+    |   ( '/' ~('*'|'=') ) => DIV {$setType(DIV);}
+    |   DIV_ASSIGN {$setType(DIV_ASSIGN);}
     ;
 
 DOLLAR_REGEXP_LITERAL
@@ -4026,14 +4026,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
@@ -4042,13 +4039,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/2fdfc9c2/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'
+    }
 }


Mime
View raw message