[
https://issues.apache.org/jira/browse/GROOVY-7928?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Juan Martín Sotuyo Dodero updated GROOVY-7928:
----------------------------------------------
Description:
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 GroovyTokenizer 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
was:
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 GroovyTokenizer 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 in file " + sourceCode.getFileName() + " 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
> 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 GroovyTokenizer 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)