Klenk Michael | 7 May 16:47
Picon
Picon

[groovy-dev] Problems with GroovyLexer

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 $?

Thanks for your help.

Greets Mike

--

-- 

Michael Klenk
E-Mail: surffan@...

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane