Examples of TokenRewriteStream


Examples of org.antlr.runtime.TokenRewriteStream

      "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.fill();
    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);
  }
View Full Code Here

Examples of org.antlr.runtime.TokenRewriteStream

      "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.fill();
    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);
  }
View Full Code Here

Examples of org.antlr.runtime.TokenRewriteStream

      "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.fill();
    tokens.insertBefore(1, "x");
    tokens.insertBefore(2, "y");
    tokens.insertBefore(0, "z");
    String result = tokens.toString();
    String expecting = "zaxbyc";
    assertEquals(expecting, result);
  }
View Full Code Here

Examples of org.antlr.runtime.TokenRewriteStream

      "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.fill();
    tokens.replace(1, 2, "foo");
    tokens.replace(0, 3, "bar"); // wipes prior nested replace
    String result = tokens.toString();
    String expecting = "bar";
    assertEquals(expecting, result);
  }
View Full Code Here

Examples of org.antlr.runtime.TokenRewriteStream

      "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.fill();
    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 <ReplaceOp@[@1,1:1='b',<5>,1:1]..[@2,2:2='c',<6>,1:2]:\"foo\"> overlap with previous <ReplaceOp@[@0,0:0='a',<4>,1:0]..[@3,3:3='c',<6>,1:3]:\"bar\">";
View Full Code Here

Examples of org.antlr.runtime.TokenRewriteStream

      "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.fill();
    tokens.replace(1, 2, "foo");
    tokens.replace(0, 2, "bar"); // wipes prior nested replace
    String result = tokens.toString();
    String expecting = "barc";
    assertEquals(expecting, result);
  }
View Full Code Here

Examples of org.antlr.runtime.TokenRewriteStream

      "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.fill();
    tokens.replace(1, 2, "foo");
    tokens.replace(1, 3, "bar"); // wipes prior nested replace
    String result = tokens.toString();
    String expecting = "abar";
    assertEquals(expecting, result);
  }
View Full Code Here

Examples of org.antlr.runtime.TokenRewriteStream

      "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.fill();
    tokens.replace(1, 2, "foo");
    tokens.replace(1, 2, "foo"); // drop previous, identical
    String result = tokens.toString();
    String expecting = "afooc";
    assertEquals(expecting, result);
  }
View Full Code Here

Examples of org.antlr.runtime.TokenRewriteStream

      "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.fill();
    tokens.insertBefore(1, "foo");
    tokens.replace(1, 2, "foo"); // kill prev insert
    String result = tokens.toString();
    String expecting = "afoofoo";
    assertEquals(expecting, result);
  }
View Full Code Here

Examples of org.antlr.runtime.TokenRewriteStream

      "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.fill();
    tokens.insertBefore(1, "x");
    tokens.replace(2, 3, "foo");
    String result = tokens.toString();
    String expecting = "axbfoo";
    assertEquals(expecting, result);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.