Java Code Examples for org.antlr.runtime.TokenRewriteStream#LT
The following examples show how to use
org.antlr.runtime.TokenRewriteStream#LT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testOverlappingReplace2() throws Exception { Grammar g = new Grammar( "lexer grammar t;\n"+ "A : 'a';\n" + "B : 'b';\n" + "C : 'c';\n"); CharStream input = new ANTLRStringStream("abcc"); Interpreter lexEngine = new Interpreter(g, input); TokenRewriteStream tokens = new TokenRewriteStream(lexEngine); tokens.LT(1); // fill buffer tokens.replace(0, 3, "bar"); tokens.replace(1, 2, "foo"); // cannot split earlier replace Exception exc = null; try { tokens.toString(); } catch (IllegalArgumentException iae) { exc = iae; } String expecting = "replace op boundaries of <[email protected]:\"foo\"> overlap with previous <[email protected]:\"bar\">"; assertNotNull(exc); assertEquals(expecting, exc.getMessage()); }
Example 2
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testReplaceThenReplaceSuperset() throws Exception { Grammar g = new Grammar( "lexer grammar t;\n"+ "A : 'a';\n" + "B : 'b';\n" + "C : 'c';\n"); CharStream input = new ANTLRStringStream("abcccba"); Interpreter lexEngine = new Interpreter(g, input); TokenRewriteStream tokens = new TokenRewriteStream(lexEngine); tokens.LT(1); // fill buffer tokens.replace(2, 4, "xyz"); tokens.replace(3, 5, "foo"); // overlaps, error Exception exc = null; try { tokens.toString(); } catch (IllegalArgumentException iae) { exc = iae; } String expecting = "replace op boundaries of <[email protected]:\"foo\"> overlap with previous <[email protected]:\"xyz\">"; assertNotNull(exc); assertEquals(expecting, exc.getMessage()); }
Example 3
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testDropPrevCoveredInsert() throws Exception { Grammar g = new Grammar( "lexer grammar t;\n"+ "A : 'a';\n" + "B : 'b';\n" + "C : 'c';\n"); CharStream input = new ANTLRStringStream("abcc"); Interpreter lexEngine = new Interpreter(g, input); TokenRewriteStream tokens = new TokenRewriteStream(lexEngine); tokens.LT(1); // fill buffer tokens.insertBefore(1, "foo"); tokens.replace(1, 2, "foo"); // kill prev insert String result = tokens.toString(); String expecting = "afooc"; assertEquals(expecting, result); }
Example 4
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testReplaceThenInsertAfterLastIndex() 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(2, "x"); tokens.insertAfter(2, "y"); String result = tokens.toString(); String expecting = "abxy"; assertEquals(expecting, result); }
Example 5
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testDropIdenticalReplace() throws Exception { Grammar g = new Grammar( "lexer grammar t;\n"+ "A : 'a';\n" + "B : 'b';\n" + "C : 'c';\n"); CharStream input = new ANTLRStringStream("abcc"); Interpreter lexEngine = new Interpreter(g, input); TokenRewriteStream tokens = new TokenRewriteStream(lexEngine); tokens.LT(1); // fill buffer tokens.replace(1, 2, "foo"); tokens.replace(1, 2, "foo"); // drop previous, identical String result = tokens.toString(); String expecting = "afooc"; assertEquals(expecting, result); }
Example 6
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void test2InsertThenReplaceIndex0() 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.insertBefore(0, "x"); tokens.insertBefore(0, "y"); tokens.replace(0, "z"); String result = tokens.toString(); String expecting = "zbc"; assertEquals(expecting, result); }
Example 7
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void test2InsertMiddleIndex() 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.insertBefore(1, "x"); tokens.insertBefore(1, "y"); String result = tokens.toString(); String expecting = "ayxbc"; assertEquals(expecting, result); }
Example 8
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testReplaceRangeThenInsertAfterRightEdge() throws Exception { Grammar g = new Grammar( "lexer grammar t;\n"+ "A : 'a';\n" + "B : 'b';\n" + "C : 'c';\n"); CharStream input = new ANTLRStringStream("abcccba"); Interpreter lexEngine = new Interpreter(g, input); TokenRewriteStream tokens = new TokenRewriteStream(lexEngine); tokens.LT(1); // fill buffer tokens.replace(2, 4, "x"); tokens.insertAfter(4, "y"); String result = tokens.toString(); String expecting = "abxyba"; assertEquals(expecting, result); }
Example 9
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testInsertInPriorReplace() 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, 2, "x"); tokens.insertBefore(1, "0"); Exception exc = null; try { tokens.toString(); } catch (IllegalArgumentException iae) { exc = iae; } String expecting = "insert op <InsertBeforeOp@1:\"0\"> within boundaries of previous <[email protected]:\"x\">"; assertNotNull(exc); assertEquals(expecting, exc.getMessage()); }
Example 10
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void test2ReplaceMiddleIndex1InsertBefore() 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.insertBefore(0, "_"); tokens.replace(1, "x"); tokens.replace(1, "y"); String result = tokens.toString(); String expecting = "_ayc"; assertEquals(expecting, result); }
Example 11
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testCombineInsertOnLeftWithReplace() 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, 2, "foo"); tokens.insertBefore(0, "z"); // combine with left edge of rewrite String result = tokens.toString(); String expecting = "zfoo"; assertEquals(expecting, result); }
Example 12
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testCombineInsertOnLeftWithDelete() 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.delete(0, 2); tokens.insertBefore(0, "z"); // combine with left edge of rewrite String result = tokens.toString(); String expecting = "z"; // make sure combo is not znull assertEquals(expecting, result); }
Example 13
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testCombine3Inserts() 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.insertBefore(1, "x"); tokens.insertBefore(0, "y"); tokens.insertBefore(1, "z"); String result = tokens.toString(); String expecting = "yazxbc"; assertEquals(expecting, result); }
Example 14
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testReplaceSingleMiddleThenOverlappingSuperset() throws Exception { Grammar g = new Grammar( "lexer grammar t;\n"+ "A : 'a';\n" + "B : 'b';\n" + "C : 'c';\n"); CharStream input = new ANTLRStringStream("abcba"); Interpreter lexEngine = new Interpreter(g, input); TokenRewriteStream tokens = new TokenRewriteStream(lexEngine); tokens.LT(1); // fill buffer tokens.replace(2, 2, "xyz"); tokens.replace(0, 3, "foo"); String result = tokens.toString(); String expecting = "fooa"; assertEquals(expecting, result); }
Example 15
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testOverlappingReplace3() throws Exception { Grammar g = new Grammar( "lexer grammar t;\n"+ "A : 'a';\n" + "B : 'b';\n" + "C : 'c';\n"); CharStream input = new ANTLRStringStream("abcc"); Interpreter lexEngine = new Interpreter(g, input); TokenRewriteStream tokens = new TokenRewriteStream(lexEngine); tokens.LT(1); // fill buffer tokens.replace(1, 2, "foo"); tokens.replace(0, 2, "bar"); // wipes prior nested replace String result = tokens.toString(); String expecting = "barc"; assertEquals(expecting, result); }
Example 16
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
public void testDisjointInserts() 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.insertBefore(1, "x"); tokens.insertBefore(2, "y"); tokens.insertBefore(0, "z"); String result = tokens.toString(); String expecting = "zaxbyc"; assertEquals(expecting, result); }
Example 17
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 5 votes |
public void testInsertBeforeIndex0() 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.insertBefore(0, "0"); String result = tokens.toString(); String expecting = "0abc"; assertEquals(expecting, result); }
Example 18
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 5 votes |
public void testReplaceMiddleIndex() 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(1, "x"); String result = tokens.toString(); String expecting = "axc"; assertEquals(expecting, result); }
Example 19
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 5 votes |
public void testReplaceAll() throws Exception { Grammar g = new Grammar( "lexer grammar t;\n"+ "A : 'a';\n" + "B : 'b';\n" + "C : 'c';\n"); CharStream input = new ANTLRStringStream("abcccba"); Interpreter lexEngine = new Interpreter(g, input); TokenRewriteStream tokens = new TokenRewriteStream(lexEngine); tokens.LT(1); // fill buffer tokens.replace(0, 6, "x"); String result = tokens.toString(); String expecting = "x"; assertEquals(expecting, result); }
Example 20
Source File: TestTokenRewriteStream.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 5 votes |
public void testReplaceIndex0() 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"); String result = tokens.toString(); String expecting = "xbc"; assertEquals(expecting, result); }