Package org.antlr.v4.runtime

Examples of org.antlr.v4.runtime.TokenStreamRewriter.replace()


    String input = "abc";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.replace(0, 2, "x");
    tokens.insertBefore(1, "0");
    Exception exc = null;
    try {
      tokens.getText();
    }
View Full Code Here


    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.insertBefore(0, "0");
    tokens.replace(0, "x");
    stream.fill();
// supercedes insert at 0
    String result = tokens.getText();
    String expecting = "0xbc";
    assertEquals(expecting, result);
View Full Code Here

    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.insertBefore(0, "x");
    tokens.insertBefore(0, "y");
    tokens.replace(0, "z");
    String result = tokens.getText();
    String expecting = "yxzbc";
    assertEquals(expecting, result);
  }
View Full Code Here

    String input = "abc";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.replace(2, "x");
    tokens.insertBefore(2, "y");
    String result = tokens.getText();
    String expecting = "abyx";
    assertEquals(expecting, result);
  }
View Full Code Here

    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.insertBefore(2, "y");
    tokens.replace(2, "x");
    String result = tokens.getText();
    String expecting = "abyx";
    assertEquals(expecting, result);
  }
View Full Code Here

    String input = "abc";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.replace(2, "x");
    tokens.insertAfter(2, "y");
    String result = tokens.getText();
    String expecting = "abxy";
    assertEquals(expecting, result);
  }
View Full Code Here

    String input = "abcccba";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.replace(2, 4, "x");
    tokens.insertBefore(2, "y");
    String result = tokens.getText();
    String expecting = "abyxba";
    assertEquals(expecting, result);
  }
View Full Code Here

    String input = "abcccba";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.replace(2, 4, "x");
    tokens.insertBefore(4, "y");
    stream.fill(); // no effect; within range of a replace
    Exception exc = null;
    try {
      tokens.getText();
View Full Code Here

    String input = "abcccba";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.replace(2, 4, "x");
    tokens.insertAfter(4, "y");
    String result = tokens.getText();
    String expecting = "abxyba";
    assertEquals(expecting, result);
  }
View Full Code Here

    String input = "abcccba";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.replace(0, 6, "x");
    String result = tokens.getText();
    String expecting = "x";
    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.