Package org.antlr.runtime

Examples of org.antlr.runtime.CommonToken


    t.replaceChildren(0, 0, newChild);
  }

  @Test public void testReplaceWithOneChildren() throws Exception {
    // assume token type 99 and use text
    CommonTree t = new CommonTree(new CommonToken(99,"a"));
    CommonTree c0 = new CommonTree(new CommonToken(99, "b"));
    t.addChild(c0);

    CommonTree newChild = new CommonTree(new CommonToken(99, "c"));
    t.replaceChildren(0, 0, newChild);
    String expecting = "(a c)";
    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }
View Full Code Here


    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }

  @Test public void testReplaceInMiddle() throws Exception {
    CommonTree t = new CommonTree(new CommonToken(99, "a"));
    t.addChild(new CommonTree(new CommonToken(99, "b")));
    t.addChild(new CommonTree(new CommonToken(99, "c"))); // index 1
    t.addChild(new CommonTree(new CommonToken(99, "d")));

    CommonTree newChild = new CommonTree(new CommonToken(99,"x"));
    t.replaceChildren(1, 1, newChild);
    String expecting = "(a b x d)";
    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }
View Full Code Here

    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }

  @Test public void testReplaceAtLeft() throws Exception {
    CommonTree t = new CommonTree(new CommonToken(99, "a"));
    t.addChild(new CommonTree(new CommonToken(99, "b"))); // index 0
    t.addChild(new CommonTree(new CommonToken(99, "c")));
    t.addChild(new CommonTree(new CommonToken(99, "d")));

    CommonTree newChild = new CommonTree(new CommonToken(99,"x"));
    t.replaceChildren(0, 0, newChild);
    String expecting = "(a x c d)";
    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }
View Full Code Here

    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }

  @Test public void testReplaceAtRight() throws Exception {
    CommonTree t = new CommonTree(new CommonToken(99, "a"));
    t.addChild(new CommonTree(new CommonToken(99, "b")));
    t.addChild(new CommonTree(new CommonToken(99, "c")));
    t.addChild(new CommonTree(new CommonToken(99, "d"))); // index 2

    CommonTree newChild = new CommonTree(new CommonToken(99,"x"));
    t.replaceChildren(2, 2, newChild);
    String expecting = "(a b c x)";
    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }
View Full Code Here

    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }

  @Test public void testReplaceOneWithTwoAtLeft() throws Exception {
    CommonTree t = new CommonTree(new CommonToken(99, "a"));
    t.addChild(new CommonTree(new CommonToken(99, "b")));
    t.addChild(new CommonTree(new CommonToken(99, "c")));
    t.addChild(new CommonTree(new CommonToken(99, "d")));

    CommonTree newChildren = (CommonTree)adaptor.nil();
    newChildren.addChild(new CommonTree(new CommonToken(99,"x")));
    newChildren.addChild(new CommonTree(new CommonToken(99,"y")));

    t.replaceChildren(0, 0, newChildren);
    String expecting = "(a x y c d)";
    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
View Full Code Here

    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }

  @Test public void testReplaceOneWithTwoAtRight() throws Exception {
    CommonTree t = new CommonTree(new CommonToken(99, "a"));
    t.addChild(new CommonTree(new CommonToken(99, "b")));
    t.addChild(new CommonTree(new CommonToken(99, "c")));
    t.addChild(new CommonTree(new CommonToken(99, "d")));

    CommonTree newChildren = (CommonTree)adaptor.nil();
    newChildren.addChild(new CommonTree(new CommonToken(99,"x")));
    newChildren.addChild(new CommonTree(new CommonToken(99,"y")));

    t.replaceChildren(2, 2, newChildren);
    String expecting = "(a b c x y)";
    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
View Full Code Here

    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }

  @Test public void testReplaceOneWithTwoInMiddle() throws Exception {
    CommonTree t = new CommonTree(new CommonToken(99, "a"));
    t.addChild(new CommonTree(new CommonToken(99, "b")));
    t.addChild(new CommonTree(new CommonToken(99, "c")));
    t.addChild(new CommonTree(new CommonToken(99, "d")));

    CommonTree newChildren = (CommonTree)adaptor.nil();
    newChildren.addChild(new CommonTree(new CommonToken(99,"x")));
    newChildren.addChild(new CommonTree(new CommonToken(99,"y")));

    t.replaceChildren(1, 1, newChildren);
    String expecting = "(a b x y d)";
    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
View Full Code Here

    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }

  @Test public void testReplaceTwoWithOneAtLeft() throws Exception {
    CommonTree t = new CommonTree(new CommonToken(99, "a"));
    t.addChild(new CommonTree(new CommonToken(99, "b")));
    t.addChild(new CommonTree(new CommonToken(99, "c")));
    t.addChild(new CommonTree(new CommonToken(99, "d")));

    CommonTree newChild = new CommonTree(new CommonToken(99,"x"));

    t.replaceChildren(0, 1, newChild);
    String expecting = "(a x d)";
    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
View Full Code Here

    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }

  @Test public void testReplaceTwoWithOneAtRight() throws Exception {
    CommonTree t = new CommonTree(new CommonToken(99, "a"));
    t.addChild(new CommonTree(new CommonToken(99, "b")));
    t.addChild(new CommonTree(new CommonToken(99, "c")));
    t.addChild(new CommonTree(new CommonToken(99, "d")));

    CommonTree newChild = new CommonTree(new CommonToken(99,"x"));

    t.replaceChildren(1, 2, newChild);
    String expecting = "(a b x)";
    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
View Full Code Here

    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
  }

  @Test public void testReplaceAllWithOne() throws Exception {
    CommonTree t = new CommonTree(new CommonToken(99, "a"));
    t.addChild(new CommonTree(new CommonToken(99, "b")));
    t.addChild(new CommonTree(new CommonToken(99, "c")));
    t.addChild(new CommonTree(new CommonToken(99, "d")));

    CommonTree newChild = new CommonTree(new CommonToken(99,"x"));

    t.replaceChildren(0, 2, newChild);
    String expecting = "(a x)";
    assertEquals(expecting, t.toStringTree());
    t.sanityCheckParentAndChildIndexes();
View Full Code Here

TOP

Related Classes of org.antlr.runtime.CommonToken

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.