Package org.antlr.runtime

Examples of org.antlr.runtime.CommonToken


  @Test public void testList() throws Exception {
    // ^(nil 101 102 103)
    CommonTree r0 = new CommonTree((Token)null);
    CommonTree c0, c1, c2;
    r0.addChild(c0=new CommonTree(new CommonToken(101)));
    r0.addChild(c1=new CommonTree(new CommonToken(102)));
    r0.addChild(c2=new CommonTree(new CommonToken(103)));

    assertNull(r0.parent);
    assertEquals(-1, r0.childIndex);
    assertEquals(r0, c0.parent);
    assertEquals(0, c0.childIndex);
View Full Code Here


  }

  @Test public void testList2() throws Exception {
    // Add child ^(nil 101 102 103) to root 5
    // should pull 101 102 103 directly to become 5's child list
    CommonTree root = new CommonTree(new CommonToken(5));

    // child tree
    CommonTree r0 = new CommonTree((Token)null);
    CommonTree c0, c1, c2;
    r0.addChild(c0=new CommonTree(new CommonToken(101)));
    r0.addChild(c1=new CommonTree(new CommonToken(102)));
    r0.addChild(c2=new CommonTree(new CommonToken(103)));

    root.addChild(r0);

    assertNull(root.parent);
    assertEquals(-1, root.childIndex);
View Full Code Here

  }

  @Test public void testAddListToExistChildren() throws Exception {
    // Add child ^(nil 101 102 103) to root ^(5 6)
    // should add 101 102 103 to end of 5's child list
    CommonTree root = new CommonTree(new CommonToken(5));
    root.addChild(new CommonTree(new CommonToken(6)));

    // child tree
    CommonTree r0 = new CommonTree((Token)null);
    CommonTree c0, c1, c2;
    r0.addChild(c0=new CommonTree(new CommonToken(101)));
    r0.addChild(c1=new CommonTree(new CommonToken(102)));
    r0.addChild(c2=new CommonTree(new CommonToken(103)));

    root.addChild(r0);

    assertNull(root.parent);
    assertEquals(-1, root.childIndex);
View Full Code Here

    assertEquals(3, c2.childIndex);
  }

  @Test public void testDupTree() throws Exception {
    // ^(101 ^(102 103 ^(106 107) ) 104 105)
    CommonTree r0 = new CommonTree(new CommonToken(101));
    CommonTree r1 = new CommonTree(new CommonToken(102));
    r0.addChild(r1);
    r1.addChild(new CommonTree(new CommonToken(103)));
    Tree r2 = new CommonTree(new CommonToken(106));
    r2.addChild(new CommonTree(new CommonToken(107)));
    r1.addChild(r2);
    r0.addChild(new CommonTree(new CommonToken(104)));
    r0.addChild(new CommonTree(new CommonToken(105)));

    CommonTree dup = (CommonTree)(new CommonTreeAdaptor()).dupTree(r0);

    assertNull(dup.parent);
    assertEquals(-1, dup.childIndex);
View Full Code Here

    dup.sanityCheckParentAndChildIndexes();
  }

  @Test public void testBecomeRoot() throws Exception {
    // 5 becomes new root of ^(nil 101 102 103)
    CommonTree newRoot = new CommonTree(new CommonToken(5));

    CommonTree oldRoot = new CommonTree((Token)null);
    oldRoot.addChild(new CommonTree(new CommonToken(101)));
    oldRoot.addChild(new CommonTree(new CommonToken(102)));
    oldRoot.addChild(new CommonTree(new CommonToken(103)));

    TreeAdaptor adaptor = new CommonTreeAdaptor();
    adaptor.becomeRoot(newRoot, oldRoot);
    newRoot.sanityCheckParentAndChildIndexes();
  }
View Full Code Here

    newRoot.sanityCheckParentAndChildIndexes();
  }

  @Test public void testBecomeRoot2() throws Exception {
    // 5 becomes new root of ^(101 102 103)
    CommonTree newRoot = new CommonTree(new CommonToken(5));

    CommonTree oldRoot = new CommonTree(new CommonToken(101));
    oldRoot.addChild(new CommonTree(new CommonToken(102)));
    oldRoot.addChild(new CommonTree(new CommonToken(103)));

    TreeAdaptor adaptor = new CommonTreeAdaptor();
    adaptor.becomeRoot(newRoot, oldRoot);
    newRoot.sanityCheckParentAndChildIndexes();
  }
View Full Code Here

  }

  @Test public void testBecomeRoot3() throws Exception {
    // ^(nil 5) becomes new root of ^(nil 101 102 103)
    CommonTree newRoot = new CommonTree((Token)null);
    newRoot.addChild(new CommonTree(new CommonToken(5)));

    CommonTree oldRoot = new CommonTree((Token)null);
    oldRoot.addChild(new CommonTree(new CommonToken(101)));
    oldRoot.addChild(new CommonTree(new CommonToken(102)));
    oldRoot.addChild(new CommonTree(new CommonToken(103)));

    TreeAdaptor adaptor = new CommonTreeAdaptor();
    adaptor.becomeRoot(newRoot, oldRoot);
    newRoot.sanityCheckParentAndChildIndexes();
  }
View Full Code Here

  }

  @Test public void testBecomeRoot5() throws Exception {
    // ^(nil 5) becomes new root of ^(101 102 103)
    CommonTree newRoot = new CommonTree((Token)null);
    newRoot.addChild(new CommonTree(new CommonToken(5)));

    CommonTree oldRoot = new CommonTree(new CommonToken(101));
    oldRoot.addChild(new CommonTree(new CommonToken(102)));
    oldRoot.addChild(new CommonTree(new CommonToken(103)));

    TreeAdaptor adaptor = new CommonTreeAdaptor();
    adaptor.becomeRoot(newRoot, oldRoot);
    newRoot.sanityCheckParentAndChildIndexes();
  }
View Full Code Here

  @Test public void testBecomeRoot6() throws Exception {
    // emulates construction of ^(5 6)
    CommonTree root_0 = (CommonTree)adaptor.nil();
    CommonTree root_1 = (CommonTree)adaptor.nil();
    root_1 = (CommonTree)adaptor.becomeRoot(new CommonTree(new CommonToken(5)), root_1);

    adaptor.addChild(root_1, new CommonTree(new CommonToken(6)));

    adaptor.addChild(root_0, root_1);

    root_0.sanityCheckParentAndChildIndexes();
  }
View Full Code Here

  // Test replaceChildren

  @Test(expected = IllegalArgumentException.class)
  public void testReplaceWithNoChildren() throws Exception {
    CommonTree t = new CommonTree(new CommonToken(101));
    CommonTree newChild = new CommonTree(new CommonToken(5));
    t.replaceChildren(0, 0, newChild);
  }
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.