Package org.antlr.runtime.tree

Examples of org.antlr.runtime.tree.CommonTree.toStringTree()


        ANTLRv3Lexer lex = new ANTLRv3Lexer(input);
        tokens = new TokenRewriteStream(lex);
        ANTLRv3Parser g = new ANTLRv3Parser(tokens);
        ANTLRv3Parser.grammarDef_return r = g.grammarDef();
        CommonTree t = r.getTree();
        if (tree_option) System.out.println(t.toStringTree());
        rewrite(g.getTreeAdaptor(),t,g.getTokenNames());
    }

    public void rewrite(TreeAdaptor adaptor, CommonTree t, String[] tokenNames) throws Exception {
        TreeWizard wiz = new TreeWizard(adaptor, tokenNames);
View Full Code Here


  protected static final TreeAdaptor adaptor = new CommonTreeAdaptor();

  @Test public void testSingleNode() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("ID");
    String found = t.toStringTree();
    String expecting = "ID";
    assertEquals(expecting, found);
  }

  @Test public void testSingleNodeWithArg() throws Exception {
View Full Code Here

  }

  @Test public void testSingleNodeWithArg() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("ID[foo]");
    String found = t.toStringTree();
    String expecting = "foo";
    assertEquals(expecting, found);
  }

  @Test public void testSingleNodeTree() throws Exception {
View Full Code Here

  }

  @Test public void testSingleNodeTree() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("(A)");
    String found = t.toStringTree();
    String expecting = "A";
    assertEquals(expecting, found);
  }

  @Test public void testSingleLevelTree() throws Exception {
View Full Code Here

  }

  @Test public void testSingleLevelTree() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("(A B C D)");
    String found = t.toStringTree();
    String expecting = "(A B C D)";
    assertEquals(expecting, found);
  }

  @Test public void testListTree() throws Exception {
View Full Code Here

  }

  @Test public void testListTree() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("(nil A B C)");
    String found = t.toStringTree();
    String expecting = "A B C";
    assertEquals(expecting, found);
  }

  @Test public void testInvalidListTree() throws Exception {
View Full Code Here

  }

  @Test public void testDoubleLevelTree() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("(A (B C) (B D) E)");
    String found = t.toStringTree();
    String expecting = "(A (B C) (B D) E)";
    assertEquals(expecting, found);
  }

  @Test public void testSingleNodeIndex() throws Exception {
View Full Code Here

    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());
  }

  @Test public void testParseWithTextFails() throws Exception {
    TreeWizard wiz = new TreeWizard(adaptor, tokens);
    CommonTree t = (CommonTree)wiz.create("(A B C)");
View Full Code Here

                    Method[] methods = _return.getDeclaredMethods();
                    for(Method method : methods) {
                      if ( method.getName().equals("getTree") ) {
                        Method returnName = _return.getMethod("getTree");
                          CommonTree tree = (CommonTree) returnName.invoke(ruleReturn);
                          astString = tree.toStringTree();
                      }
                      else if ( method.getName().equals("getTemplate") ) {
                        Method returnName = _return.getMethod("getTemplate");
                        StringTemplate st = (StringTemplate) returnName.invoke(ruleReturn);
                        stString = st.toString();
View Full Code Here

                    Method[] methods = _treeReturn.getDeclaredMethods();
                  for(Method method : methods) {
                      if ( method.getName().equals("getTree") ) {
                        Method treeReturnName = _treeReturn.getMethod("getTree");
                          CommonTree returnTree = (CommonTree) treeReturnName.invoke(treeRuleReturn);
                            astString = returnTree.toStringTree();
                      }
                      else if ( method.getName().equals("getTemplate") ) {
                        Method treeReturnName = _return.getMethod("getTemplate");
                        StringTemplate st = (StringTemplate) treeReturnName.invoke(treeRuleReturn);
                        stString = st.toString();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.