[prev in list] [next in list] [prev in thread] [next in thread] 

List:       antlr-dev
Subject:    Re: [antlr-dev] TokenRewriteStream: the saga continues
From:       Terence Parr <parrt () cs ! usfca ! edu>
Date:       2008-05-28 19:08:44
Message-ID: 35022040-EC7C-4E82-9888-F9B02BCD9B31 () cs ! usfca ! edu
[Download RAW message or body]


On May 23, 2008, at 7:23 PM, Jeff Saremi wrote:

> Well, i didn't get any response to my last post on this subject. I  
> guess the code's logic is too plain to explain.
>
> However, i needed to clarify this inconsistency between the  
> documentation (javaDoc comments) and the unit tests.
>
> The following is copied from the comments for  
> "addToSortedRewriteList()". It says that "insert foo" and then  
> "insert bar" should print "foobar".

ooopsShould be barfoo.
>
>
>      *  ...  If there are
>      *  multiple insert instructions for a single index, they are  
> done in
>      *  reverse insertion order so that "insert foo" then "insert  
> bar" yields
>      *  "foobar" in front rather than "barfoo".  This is convenient  
> because
>      *  I can insert new InsertOp instructions at the index returned  
> by
>      *  the binary search.  ...
>
>
> However, in the file TestTokenRewriteStream.java (if this file is  
> still used in unit tests) I found the following test and it looks  
> like the test contradicts the comments above because the test runs  
> with success:
>
>     public void testReplaceThen2InsertSameIndex() throws Exception {
>         Grammar g = new Grammar(
>             "lexer grammar t;\n"+
>             "A : 'a';\n" +
>             "B : 'b';\n" +
>             "C : 'c';\n");
>         CharStream input = new ANTLRStringStream("abc");
>         Interpreter lexEngine = new Interpreter(g, input);
>         TokenRewriteStream tokens = new TokenRewriteStream(lexEngine);
>         tokens.LT(1); // fill buffer
>         tokens.replace(0, "x"); // replaces are done after the  
> inserts for the same index
>         tokens.insertBefore(0, "y"); // Jeff: "y" is inserted first  
> so it should come out first
>         tokens.insertBefore(0, "z"); // Jeff: "z" is inserted after  
> "y" but see the "expecting"
>         String result = tokens.toString();
>         String expecting = "zyxbc";
>         assertEquals(result, expecting); // so we didn't get "yz"  
> the way we were promised
>     }

This test seems correct to me.

Ter
_______________________________________________
antlr-dev mailing list
antlr-dev@antlr.org
http://www.antlr.org:8080/mailman/listinfo/antlr-dev
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic