[antlr-interest] TokenRewriteStream
Filipe David Manana
fdmanana at ieee.org
Sun Mar 8 11:52:22 PDT 2009
Hi Terence,
Nop, I tried it and it doesn't work either.
It seems the parser gets only the original, unmodified, token stream.
Any other suggestion?
thanks
On Sun, Mar 8, 2009 at 6:03 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
> 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
>
>
>
--
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."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090308/ac51b6cc/attachment.html
More information about the antlr-interest
mailing list