Package org.antlr.runtime.tree

Examples of org.antlr.runtime.tree.CommonTree


    assertTrue(valid);
  }

  @Test public void testParseWithText2() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("(A B[T__32] (C (D E[a])))");
    // C pattern has no text arg so despite [bar] in t, no need
    // to match text--check structure only.
    boolean valid = wiz.parse(t, "(A B[foo] C)");
    assertEquals("(A T__32 (C (D a)))", t.toStringTree());
  }
View Full Code Here


    assertEquals("(A T__32 (C (D a)))", t.toStringTree());
  }

  @Test public void testParseWithTextFails() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("(A B C)");
    boolean valid = wiz.parse(t, "(A[foo] B C)");
    assertTrue(!valid); // fails
  }
View Full Code Here

    assertTrue(!valid); // fails
  }

  @Test public void testParseLabels() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("(A B C)");
    Map<String, Object> labels = new HashMap<String, Object>();
    boolean valid = wiz.parse(t, "(%a:A %b:B %c:C)", labels);
    assertTrue(valid);
    assertEquals("A", labels.get("a").toString());
    assertEquals("B", labels.get("b").toString());
View Full Code Here

    assertEquals("C", labels.get("c").toString());
  }

  @Test public void testParseWithWildcardLabels() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("(A B C)");
    Map<String, Object> labels = new HashMap<String, Object>();
    boolean valid = wiz.parse(t, "(A %b:. %c:.)", labels);
    assertTrue(valid);
    assertEquals("B", labels.get("b").toString());
    assertEquals("C", labels.get("c").toString());
View Full Code Here

    assertEquals("C", labels.get("c").toString());
  }

  @Test public void testParseLabelsAndTestText() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("(A B[foo] C)");
    Map<String, Object> labels = new HashMap<String, Object>();
    boolean valid = wiz.parse(t, "(%a:A %b:B[foo] %c:C)", labels);
    assertTrue(valid);
    assertEquals("A", labels.get("a").toString());
    assertEquals("foo", labels.get("b").toString());
View Full Code Here

    assertEquals("C", labels.get("c").toString());
  }

  @Test public void testParseLabelsInNestedTree() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("(A (B C) (D E))");
    Map<String, Object> labels = new HashMap<String, Object>();
    boolean valid = wiz.parse(t, "(%a:A (%b:B %c:C) (%d:D %e:E) )", labels);
    assertTrue(valid);
    assertEquals("A", labels.get("a").toString());
    assertEquals("B", labels.get("b").toString());
View Full Code Here

    assertEquals("E", labels.get("e").toString());
  }

  @Test public void testEquals() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t1 = (CommonTree)wiz.create("(A B C)");
    CommonTree t2 = (CommonTree)wiz.create("(A B C)");
    boolean same = TreeWizard.equals(t1, t2, adaptor);
    assertTrue(same);
  }
View Full Code Here

    assertTrue(same);
  }

  @Test public void testEqualsWithText() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t1 = (CommonTree)wiz.create("(A B[foo] C)");
    CommonTree t2 = (CommonTree)wiz.create("(A B[foo] C)");
    boolean same = TreeWizard.equals(t1, t2, adaptor);
    assertTrue(same);
  }
View Full Code Here

    assertTrue(same);
  }
 
  @Test public void testEqualsWithMismatchedText() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t1 = (CommonTree)wiz.create("(A B[foo] C)");
    CommonTree t2 = (CommonTree)wiz.create("(A B C)");
    boolean same = TreeWizard.equals(t1, t2, adaptor);
    assertTrue(!same);
  }
View Full Code Here

    assertTrue(!same);
  }

  @Test public void testFindPattern() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("(A B C (A[foo] B[bar]) (D (A[big] B[dog])))");
    final List<? extends Object> subtrees = wiz.find(t, "(A B)");
    List<? extends Object> elements = subtrees;
    String found = elements.toString();
    String expecting = "[foo, big]";
    assertEquals(expecting, found);
View Full Code Here

TOP

Related Classes of org.antlr.runtime.tree.CommonTree

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.