[antlr-interest] TokenRewriteStream

Terence Parr parrt at cs.usfca.edu
Sun Mar 8 10:03:50 PDT 2009


maybe index should be size-1?
T
On Mar 8, 2009, at 3:48 AM, Filipe David Manana wrote:

> Hello,
>
> I am trying to add a token into the token stream before the parser's  
> starting rule (method) is invoked.
> I am doing it using a TokenRewriteStream and like this:
>
>         ANTLRInputStream input = new ANTLRInputStream(inputStream);
>         this.lexer = new JavaScriptLexer(input);
>         TokenRewriteStream tokens = new TokenRewriteStream(lexer);
>
>         // debug
>         System.err.println("token stream: " + tokens.toString());
>
>         tokens.insertAfter(tokens.getTokens().size(), ";");
>
>         this.parser = new JavaScriptParser(tokens);
>
>         // debug
>         System.err.println("token stream: " + tokens.toString());
>         System.err.println("token index: " + tokens.index());
>
> The problem is that the parser seems to ignore the appended token.
> The original token stream is:   "var a = 1<EOF>"
> The output of the previous println statements is:
>
> token stream:
> token stream: var a = 1;
>
> What am I doing wrong?
> Or is there a better way to do it?
>
> thank you
>
>
> -- 
> Filipe David Manana,
> fdmanana at ieee.org
> PGP key - http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC569452B
>
> "Reasonable men adapt themselves to the world.
> Unreasonable men adapt the world to themselves.
> That's why all progress depends on unreasonable men."
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090308/53f74198/attachment.html 


More information about the antlr-interest mailing list