Package org.antlr.v4.runtime

Examples of org.antlr.v4.runtime.TokenStreamRewriter


                       "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.replace(2, "x");
    String result = tokens.getText();
    String expecting = "abx";
    assertEquals(expecting, result);
  }
View Full Code Here


                       "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.replace(1, "x");
    String result = tokens.getText();
    String expecting = "axc";
    assertEquals(expecting, result);
  }
View Full Code Here

    // Input:  x = 3 * 0;
    String input = "x = 3 * 0;";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);
    tokens.replace(4, 8, "0");
    stream.fill();
// replace 3 * 0 with 0

    String result = tokens.getTokenStream().getText();
    String expecting = "x = 3 * 0;";
    assertEquals(expecting, result);

    result = tokens.getText();
    expecting = "x = 0;";
    assertEquals(expecting, result);

    result = tokens.getText(Interval.of(0, 9));
    expecting = "x = 0;";
    assertEquals(expecting, result);

    result = tokens.getText(Interval.of(4, 8));
    expecting = "0";
    assertEquals(expecting, result);
  }
View Full Code Here

    // Input:  x = 3 * 0 + 2 * 0;
    String input = "x = 3 * 0 + 2 * 0;";
    LexerInterpreter lexEngine = g.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream stream = new CommonTokenStream(lexEngine);
    stream.fill();
    TokenStreamRewriter tokens = new TokenStreamRewriter(stream);

    String result = tokens.getTokenStream().getText();
    String expecting = "x = 3 * 0 + 2 * 0;";
    assertEquals(expecting, result);

    tokens.replace(4, 8, "0");
    stream.fill();
// replace 3 * 0 with 0
    result = tokens.getText();
    expecting = "x = 0 + 2 * 0;";
    assertEquals(expecting, result);

    result = tokens.getText(Interval.of(0, 17));
    expecting = "x = 0 + 2 * 0;";
    assertEquals(expecting, result);

    result = tokens.getText(Interval.of(4, 8));
    expecting = "0";
    assertEquals(expecting, result);

    result = tokens.getText(Interval.of(0, 8));
    expecting = "x = 0";
    assertEquals(expecting, result);

    result = tokens.getText(Interval.of(12, 16));
    expecting = "2 * 0";
    assertEquals(expecting, result);

    tokens.insertAfter(17, "// comment");
    result = tokens.getText(Interval.of(12, 18));
    expecting = "2 * 0;// comment";
    assertEquals(expecting, result);

    result = tokens.getText(Interval.of(0, 8));
    stream.fill();
// try again after insert at end
    expecting = "x = 0";
    assertEquals(expecting, result);
  }
View Full Code Here

                       "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.replace(1, "x");
    tokens.replace(1, "y");
    String result = tokens.getText();
    String expecting = "ayc";
    assertEquals(expecting, result);
  }
View Full Code Here

                       "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(0, "_");
    tokens.replace(1, "x");
    tokens.replace(1, "y");
    String result = tokens.getText();
    String expecting = "_ayc";
    assertEquals(expecting, result);
  }
View Full Code Here

                       "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.replace(1, "x");
    tokens.delete(1);
    String result = tokens.getText();
    String expecting = "ac";
    assertEquals(expecting, result);
  }
View Full Code Here

                       "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.replace(0, 2, "x");
    tokens.insertBefore(1, "0");
    Exception exc = null;
    try {
      tokens.getText();
    }
    catch (IllegalArgumentException iae) {
      exc = iae;
    }
    String expecting = "insert op <InsertBeforeOp@[@1,1:1='b',<2>,1:1]:\"0\"> within boundaries of previous <ReplaceOp@[@0,0:0='a',<1>,1:0]..[@2,2:2='c',<3>,1:2]:\"x\">";
View Full Code Here

                       "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(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

                       "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(1, "y");
    String result = tokens.getText();
    String expecting = "ayxbc";
    assertEquals(expecting, result);
  }
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.TokenStreamRewriter

Copyright © 2018 www.massapicom. 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.