[ 
https://issues.apache.org/jira/browse/GROOVY-7928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15465759#comment-15465759
 ] 

Juan Martín Sotuyo Dodero commented on GROOVY-7928:
---------------------------------------------------

I've been tinkering with this a little bit, here are my findings:

{{"$var"}} -> fails with same error
{{"\$5"}} -> fails with same error
{{"$\{var\}"}} -> fails with same error
{{"$"}} -> fails with {{'illegal string body character after dollar sign; 
solution: either escape a literal dollar sign "\$5" or bracket the value 
expression "$\{5\}"'}} (this is actually correct!)

Uner no circunstances however, I get a GString containing a dollar sign to 
actually parse without error.

> Groovy antlr syntax does not parse GStrings with variables
> ----------------------------------------------------------
>
>                 Key: GROOVY-7928
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7928
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.7
>            Reporter: Juan Martín Sotuyo Dodero
>
> I'm trying to add Groovy support to PMD's CPD (copy paste detector, see 
> https://pmd.github.io/pmd-5.5.1/usage/cpd-usage.html). To do so, I'm 
> attempting to use the GroovyLexer shipped in 
> org.codehaus.groovy:groovy:2.4.7, which is generated from the groovy.g ANTLR 
> syntax file.
> My code currently is:
> {code:java}
>         GroovyLexer lexer = new 
> GroovyLexer(IOUtils.toInputStream(buffer.toString()));
>         
>         try {
>             Token token = lexer.nextToken();
>             while (token.getType() != Token.EOF_TYPE) {
>                 // Redacted for simplicity...
>                 token = lexer.nextToken();
>             }
>         } catch (TokenStreamException err) {
>             // Wrap exceptions of the Groovy tokenizer in a TokenMgrError, so 
> they are correctly handled
>             // when CPD is executed with the '--skipLexicalErrors' command 
> line option
>             throw new TokenMgrError(
>                     "Lexical error at line " + lexer.getLine() + ", column " 
> + lexer.getColumn() + ". " + err.getMessage(),
>                     TokenMgrError.LEXICAL_ERROR);
>         }
> {code}
> When parsing this simple snippet:
> {code:java}
> class BTree<K, V> extends BTreeNode<K> {
>       def add(K key, V value) {
>                       throw new Exception("$key")
>       }
> }
> {code}
> I get:
> {quote}
> Lexical error at line 5, column 34.  expecting anything but ''\n''; got it 
> anyway
> {quote}
> Changing *$key* for any constant string works just fine, the problem is with 
> GStrings actually interpolating variables.
> Thanks in advance



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to