[antlr-interest] adding content at end of rule withTokenRewriteStream

David Holroyd dave at badgers-in-foil.co.uk
Fri Feb 23 08:02:31 PST 2007


On Fri, Feb 23, 2007 at 03:52:40PM +0100, Jean Marc Vanel wrote:
> Exception in thread "main" java.lang.NullPointerException
> 	at org.antlr.runtime.TokenRewriteStream.insertAfter(TokenRewriteStream.java:300)
> ------------------
> grammar testAddContentAtEndOfRule;
> 
> @parser::members {
> 	TokenRewriteStream tokens;
> }
> 
> name_or_pointer
> @init {
>     tokens = (TokenRewriteStream)input;
> }
>     	:	NAME (star='*')?
> 		{ tokens.insertAfter( star.stop, " == after '*' ===" ); }
> 	;

Maybe put the action inside the (...)? so that it only executes if there
is a star present?


> 		CharStream input = new ANTLRStringStream ( "var" );
> 		// doesn't crash with "var*"
> 		testAddContentAtEndOfRuleLexer lex = new testAddContentAtEndOfRuleLexer(input);
> 		TokenStream tokens = new TokenRewriteStream(lex);
> 		testAddContentAtEndOfRuleParser parser = new testAddContentAtEndOfRuleParser(tokens);
> 		parser.name_or_pointer();


-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list