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".
* ... 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
}
_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org:8080/mailman/listinfo/antlr-dev