use of org.antlr.v4.runtime.TokenStreamRewriter in project antlr4 by antlr.
the class TestTokenStreamRewriter method testCombineInsertOnLeftWithDelete.
@Test
public void testCombineInsertOnLeftWithDelete() throws Exception {
LexerGrammar g = new LexerGrammar("lexer grammar T;\n" + "A : 'a';\n" + "B : 'b';\n" + "C : 'c';\n");
String input = "abc";
LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
CommonTokenStream stream = new CommonTokenStream(lexEngine);
stream.fill();
TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
tokens.delete(0, 2);
tokens.insertBefore(0, "z");
stream.fill();
// combine with left edge of rewrite
String result = tokens.getText();
String expecting = "z";
stream.fill();
// make sure combo is not znull
assertEquals(expecting, result);
}
use of org.antlr.v4.runtime.TokenStreamRewriter in project antlr4 by antlr.
the class TestTokenStreamRewriter method testLeaveAloneDisjointInsert2.
@Test
public void testLeaveAloneDisjointInsert2() throws Exception {
LexerGrammar g = new LexerGrammar("lexer grammar T;\n" + "A : 'a';\n" + "B : 'b';\n" + "C : 'c';\n");
String input = "abcc";
LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
CommonTokenStream stream = new CommonTokenStream(lexEngine);
stream.fill();
TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
tokens.replace(2, 3, "foo");
tokens.insertBefore(1, "x");
String result = tokens.getText();
String expecting = "axbfoo";
assertEquals(expecting, result);
}
use of org.antlr.v4.runtime.TokenStreamRewriter in project antlr4 by antlr.
the class TestTokenStreamRewriter method testCombine3Inserts.
@Test
public void testCombine3Inserts() throws Exception {
LexerGrammar g = new LexerGrammar("lexer grammar T;\n" + "A : 'a';\n" + "B : 'b';\n" + "C : 'c';\n");
String input = "abc";
LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
CommonTokenStream stream = new CommonTokenStream(lexEngine);
stream.fill();
TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
tokens.insertBefore(1, "x");
tokens.insertBefore(0, "y");
tokens.insertBefore(1, "z");
String result = tokens.getText();
String expecting = "yazxbc";
assertEquals(expecting, result);
}
Aggregations