[antlr-interest] Possible serious bug using setText in Antlr3

shmuel siegel antlr at shmuelhome.mine.nu
Tue Nov 14 22:16:39 PST 2006


The wiki page, "how do I strip quotes", recommends using setText to 
change the text of the token to be generated. For example

ESC : '\\' 'n' {setText("\n");};

As far as I can tell, this sets an instance variable of the lexer to the 
specified text. Emit then adds this text to generated tokens. getText 
will then preferentially return this text rather than build a string 
from the character stream. So far, so good. But nothing changes the 
instance variable back to null. So all future tokens will have the same 
text.

setting text=null in nextToken seems to work for me.


More information about the antlr-interest mailing list