Package org.antlr.runtime

Examples of org.antlr.runtime.TokenRewriteStream$DeleteOp


      "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.fill();
    tokens.replace(2, 4, "xyz");
    String result = tokens.toString(0,6);
    String expecting = "abxyzba";
    assertEquals(expecting, result);
  }
View Full Code Here


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

        // PARSE INPUT AND BUILD AST
        ANTLRInputStream input = new ANTLRInputStream(System.in);
        CMinusLexer lexer = new CMinusLexer(input);       // create lexer
        // create a buffer of tokens pulled from the lexer
        // Must use TokenRewriteStream not CommonTokenStream!
        TokenRewriteStream tokens = new TokenRewriteStream(lexer);
        CMinusParser parser = new CMinusParser(tokens);   // create parser
        CMinusParser.program_return r = parser.program(); // parse program



        // WALK TREE AND REWRITE TOKEN BUFFER
        // get the tree from the return structure for rule prog
        CommonTree t = (CommonTree)r.getTree();
        // create a stream of tree nodes from AST built by parser
        CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
        // tell it where it can find the token objects
        nodes.setTokenStream(tokens);
        Gen gen = new Gen(nodes);
        gen.program(); // invoke rule program
        System.out.println(tokens.toString()); // emit tweaked token buffer

    }
View Full Code Here

   */
  public ASTNode parse(String command, Context ctx) throws ParseException {
    LOG.info("Parsing command: " + command);

    HiveLexerX lexer = new HiveLexerX(new ANTLRNoCaseStringStream(command));
    TokenRewriteStream tokens = new TokenRewriteStream(lexer);
    if (ctx != null) {
      ctx.setTokenRewriteStream(tokens);
    }
    HiveParserX parser = new HiveParserX(tokens);
    parser.setTreeAdaptor(adaptor);
View Full Code Here

   */
  public ASTNode parse(String command, Context ctx) throws ParseException {
    LOG.info("Parsing command: " + command);

    HiveLexerX lexer = new HiveLexerX(new ANTLRNoCaseStringStream(command));
    TokenRewriteStream tokens = new TokenRewriteStream(lexer);
    if (ctx != null) {
      ctx.setTokenRewriteStream(tokens);
    }
    HiveParserX parser = new HiveParserX(tokens);
    parser.setTreeAdaptor(adaptor);
View Full Code Here

   */
  public ASTNode parse(String command, Context ctx) throws ParseException {
    LOG.info("Parsing command: " + command);

    HiveLexerX lexer = new HiveLexerX(new ANTLRNoCaseStringStream(command));
    TokenRewriteStream tokens = new TokenRewriteStream(lexer);
    if (ctx != null) {
      ctx.setTokenRewriteStream(tokens);
    }
    HiveParserX parser = new HiveParserX(tokens);
    parser.setTreeAdaptor(adaptor);
View Full Code Here

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

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

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

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

TOP

Related Classes of org.antlr.runtime.TokenRewriteStream$DeleteOp

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.