Package org.jostraca.comp.antlr.collections

Examples of org.jostraca.comp.antlr.collections.AST


        original = cursor = t;
    }

    /** Is 'sub' a subtree of 't' beginning at the root? */
    public boolean isSubtree(AST t, AST sub) {
        AST sibling;

        // the empty tree is always a subset of any tree.
        if (sub == null) {
            return true;
        }

        // if the tree is empty, return true if the subtree template is too.
        if (t == null) {
            if (sub != null) return false;
            return true;
        }

        // Otherwise, start walking sibling lists.  First mismatch, return false.
        for (sibling = t;
             sibling != null && sub != null;
             sibling = sibling.getNextSibling(), sub = sub.getNextSibling()) {
            // as a quick optimization, check roots first.
            if (sibling.getType() != sub.getType()) return false;
            // if roots match, do full match test on children.
            if (sibling.getFirstChild() != null) {
                if (!isSubtree(sibling.getFirstChild(), sub.getFirstChild())) return false;
            }
        }
        return true;
    }
View Full Code Here


    /** Find the next subtree with structure and token types equal to
     * those of 'template'.
     */
    public AST next(AST template) {
        AST t = null;
        AST sibling = null;

        if (cursor == null) {  // do nothing if no tree to work on
            return null;
        }

View Full Code Here

    return create(Token.INVALID_TYPE);
    }

    public AST create(int type) {
    Class c = getASTNodeType(type);
    AST t = create(c);
    if ( t!=null ) {
      t.initialize(type, "");
    }
    return t;
  }
View Full Code Here

    }
    return t;
  }

  public AST create(int type, String txt) {
        AST t = create(type);
    if ( t!=null ) {
      t.initialize(type, txt);
    }
        return t;
    }
View Full Code Here

   *  with a specific Java object type. Typically called when you
   *  say @[PLUS,"+",PLUSNode] in an antlr action.
   *  @since 2.7.2
   */
  public AST create(int type, String txt, String className) {
        AST t = create(className);
    if ( t!=null ) {
      t.initialize(type, txt);
    }
        return t;
    }
View Full Code Here

    /** Create a new empty AST node; if the user did not specify
     *  an AST node type, then create a default one: CommonAST.
     */
    public AST create(AST tr) {
        if (tr == null) return null;    // create(null) == null
        AST t = create(tr.getType());
    if ( t!=null ) {
      t.initialize(tr);
    }
        return t;
    }
View Full Code Here

    }
        return t;
    }

  public AST create(Token tok) {
        AST t = create(tok.getType());
    if ( t!=null ) {
      t.initialize(tok);
    }
        return t;
    }
View Full Code Here

   *  and so I must call the appropriate constructor not T().
   *
   * @since 2.7.2
   */
  public AST create(Token tok, String className) {
        AST t = createUsingCtor(tok,className);
        return t;
    }
View Full Code Here

  /**
   * @since 2.7.2
   */
  protected AST createUsingCtor(Token token, String className) {
    Class c = null;
    AST t = null;
    try {
      c = Class.forName(className);
      Class[] tokenArgType = new Class[] { org.jostraca.comp.antlr.Token.class };
      try {
        Constructor ctor = c.getConstructor(tokenArgType);
        t = (AST)ctor.newInstance(new Object[]{token}); // make a new one
      }
      catch (NoSuchMethodException e){
        // for c# conversion
        e.toString();

        // just do the regular thing if you can't find the ctor
        // Your AST must have default ctor to use this.
        t = create(c);
        if ( t!=null ) {
          t.initialize(token);
        }
      }
    }
    catch (Exception e) {
      // for c# conversion
View Full Code Here

  /**
   * @since 2.7.2
   */
  protected AST create(Class c) {
    AST t = null;
    try {
      t = (AST)c.newInstance(); // make a new one
    }
    catch (Exception e) {
      // for c# conversion
View Full Code Here

TOP

Related Classes of org.jostraca.comp.antlr.collections.AST

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.