Package org.antlr.runtime

Examples of org.antlr.runtime.CommonToken


  }

  @Test public void testList() throws Exception {
    Tree root = new CommonTree((Token)null);

    Tree t = new CommonTree(new CommonToken(101));
    t.addChild(new CommonTree(new CommonToken(102)));
    t.getChild(0).addChild(new CommonTree(new CommonToken(103)));
    t.addChild(new CommonTree(new CommonToken(104)));

    Tree u = new CommonTree(new CommonToken(105));

    root.addChild(t);
    root.addChild(u);

    TreeNodeStream stream = newStream(root);
View Full Code Here


  }

  @Test public void testFlatList() throws Exception {
    Tree root = new CommonTree((Token)null);

    root.addChild(new CommonTree(new CommonToken(101)));
    root.addChild(new CommonTree(new CommonToken(102)));
    root.addChild(new CommonTree(new CommonToken(103)));

    TreeNodeStream stream = newStream(root);
    String expecting = " 101 102 103";
    String found = toNodesOnlyString(stream);
    assertEquals(expecting, found);
View Full Code Here

  }

  @Test public void testListWithOneNode() throws Exception {
    Tree root = new CommonTree((Token)null);

    root.addChild(new CommonTree(new CommonToken(101)));

    TreeNodeStream stream = newStream(root);
    String expecting = " 101";
    String found = toNodesOnlyString(stream);
    assertEquals(expecting, found);
View Full Code Here

    found = toTokenTypeString(stream);
    assertEquals(expecting, found);
  }

  @Test public void testAoverB() throws Exception {
    Tree t = new CommonTree(new CommonToken(101));
    t.addChild(new CommonTree(new CommonToken(102)));

    TreeNodeStream stream = newStream(t);
    String expecting = " 101 102";
    String found = toNodesOnlyString(stream);
    assertEquals(expecting, found);
View Full Code Here

    assertEquals(expecting, found);
  }

  @Test public void testLT() throws Exception {
    // ^(101 ^(102 103) 104)
    Tree t = new CommonTree(new CommonToken(101));
    t.addChild(new CommonTree(new CommonToken(102)));
    t.getChild(0).addChild(new CommonTree(new CommonToken(103)));
    t.addChild(new CommonTree(new CommonToken(104)));

    TreeNodeStream stream = newStream(t);
    assertEquals(101, ((Tree)stream.LT(1)).getType());
    assertEquals(Token.DOWN, ((Tree)stream.LT(2)).getType());
    assertEquals(102, ((Tree)stream.LT(3)).getType());
View Full Code Here

  @Test public void testMarkRewindEntire() throws Exception {
    // ^(101 ^(102 103 ^(106 107) ) 104 105)
    // stream has 7 real + 6 nav nodes
    // Sequence of types: 101 DN 102 DN 103 106 DN 107 UP UP 104 105 UP EOF
    Tree r0 = new CommonTree(new CommonToken(101));
    Tree 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)));

    TreeNodeStream stream = newStream(r0);
    int m = stream.mark(); // MARK
    for (int k=1; k<=13; k++) { // consume til end
      stream.LT(1);
View Full Code Here

  @Test public void testMarkRewindInMiddle() throws Exception {
    // ^(101 ^(102 103 ^(106 107) ) 104 105)
    // stream has 7 real + 6 nav nodes
    // Sequence of types: 101 DN 102 DN 103 106 DN 107 UP UP 104 105 UP EOF
    Tree r0 = new CommonTree(new CommonToken(101));
    Tree 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)));

    TreeNodeStream stream = newStream(r0);
    for (int k=1; k<=7; k++) { // consume til middle
      //System.out.println(((Tree)stream.LT(1)).getType());
      stream.consume();
View Full Code Here

  @Test public void testMarkRewindNested() throws Exception {
    // ^(101 ^(102 103 ^(106 107) ) 104 105)
    // stream has 7 real + 6 nav nodes
    // Sequence of types: 101 DN 102 DN 103 106 DN 107 UP UP 104 105 UP EOF
    Tree r0 = new CommonTree(new CommonToken(101));
    Tree 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)));

    TreeNodeStream stream = newStream(r0);
    int m = stream.mark(); // MARK at start
    stream.consume(); // consume 101
    stream.consume(); // consume DN
View Full Code Here

  @Test public void testSeekFromStart() throws Exception {
    // ^(101 ^(102 103 ^(106 107) ) 104 105)
    // stream has 7 real + 6 nav nodes
    // Sequence of types: 101 DN 102 DN 103 106 DN 107 UP UP 104 105 UP EOF
    Tree r0 = new CommonTree(new CommonToken(101));
    Tree 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)));

    TreeNodeStream stream = newStream(r0);
    stream.seek(7);   // seek to 107
    assertEquals(107, ((Tree)stream.LT(1)).getType());
    stream.consume(); // consume 107
View Full Code Here

    @Test public void testReset() throws Exception {
        // ^(101 ^(102 103 ^(106 107) ) 104 105)
        // stream has 7 real + 6 nav nodes
        // Sequence of types: 101 DN 102 DN 103 106 DN 107 UP UP 104 105 UP EOF
        Tree r0 = new CommonTree(new CommonToken(101));
        Tree 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)));

        TreeNodeStream stream = newStream(r0);
        String v = toNodesOnlyString(stream); // scan all
        stream.reset();
        String v2 = toNodesOnlyString(stream); // scan all
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.