8 May 18:23
Re: [groovy-dev] Problems with GroovyLexer
From: Jochen Theodorou <blackdrag@...>
Subject: Re: [groovy-dev] Problems with GroovyLexer
Newsgroups: gmane.comp.lang.groovy.devel
Date: 2008-05-08 16:23:19 GMT
Subject: Re: [groovy-dev] Problems with GroovyLexer
Newsgroups: gmane.comp.lang.groovy.devel
Date: 2008-05-08 16:23:19 GMT
Klenk Michael schrieb:
> Hi all,
>
> I'm writing at a SourceCodeFormatter for the Groovy Eclipse plugin. As
> help to analyze the file for formatting it afterwards i use the
> GroovyLexer to parse the document. This works very well. But i came
> across a suspicious error.
> If i parse a string with a $ included, the Lexer got an exception. The
> code is running Groovy Code which can be executed with no problems. Here
> is a small groovy scipt to reproduce this exception:
>
> original groovy File
> -------------------------
> def i = 5
> println "i: $i"
>
> Test groovy script which throws an exception with the following output:
> -------------------------
> import org.codehaus.groovy.antlr.parser.GroovyLexer
> import antlr.Token
>
> def code = 'def i = 5\nprintln "i: $i"'
> GroovyLexer lexer = new GroovyLexer(new StringReader(code))
> Token token = null
> while ((token = lexer.nextToken()).getType() != Token.EOF_TYPE) {
> println(token)
> }
> -------------------------
> ["def",<81>,line=1,col=1]
> ["i",<84>,line=1,col=5]
> ["=",<120>,line=1,col=7]
> ["5",<194>,line=1,col=9]
> ["<newline>",<125>,line=1,col=10]
> ["println",<84>,line=2,col=1]
> ["i: ",<188>,line=2,col=9]
> ["i",<84>,line=2,col=14]
> Caught: line 2:15: unexpected char: '"'
> at lexer.run(lexer.groovy:7)
> at lexer.main(lexer.groovy)
>
> I use Groovy 1.5.6.
> Can someone explain this behavior or can tell me how to feed the
> GroovyLexer to accept strings with $?
I am not sure.... but there is probably some special code in the parser,
that prevents this problem from happening. Since I am not really an
antlr user I don't know for sure.
bye blackdrag
--
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
http://www.g2one.com/
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
RSS Feed