[antlr-interest] TokenRewriteStream
    Filipe David Manana 
    fdmanana at ieee.org
       
    Sun Mar  8 03:48:53 PDT 2009
    
    
  
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."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090308/a3d5322a/attachment.html 
    
    
More information about the antlr-interest
mailing list