[antlr-interest] Source positions for imaginary tokens

Mike Lischke mike at lischke-online.de
Wed Sep 12 08:54:20 PDT 2012


Ad,

Yes, you mentioned this already and Jim replied that this change is not good (because it might have unwanted side effects). 

> I solved this by hacking the code generator to call the createTypeToken() function instead of the createTokenText() or createTypeText() functions that the generated code normally calls. You might be able to avoid this change by using ID[$kw,""] in your grammar.


Your tip works but then I have no token text. I could as well just use "-> IDENTIFIER" then. I also tried:

test:
	(
		kw = 'XXX'
		| kw = 'YYY'
	) -> IDENTIFIER[$kw, $text]

but then the token text is not the empty string but null. Passing any other string has the same effect as passing in the empty string.

Mike
-- 
www.soft-gems.net



More information about the antlr-interest mailing list