Class AntlrUtils

java.lang.Object
ca.phon.phontalk.parser.AntlrUtils

public class AntlrUtils extends Object
Utility methods for working with antlr3 CommonTrees.
  • Constructor Details

    • AntlrUtils

      public AntlrUtils()
  • Method Details

    • createToken

      public static org.antlr.runtime.tree.CommonTree createToken(AntlrTokens tokens, String tokenName)
      Create a new common tree node with the given token type.
    • createToken

      public static org.antlr.runtime.tree.CommonTree createToken(int tokenType)
    • printTree

      public static void printTree(org.antlr.runtime.tree.CommonTree tree)
    • printTree

      public static void printTree(org.antlr.runtime.tree.CommonTree tree, OutputStream out)
    • printTree

      public static void printTree(AntlrTokens chatTokens, org.antlr.runtime.tree.CommonTree tree, int indent, PrintStream stream)
    • addTextNode

      public static void addTextNode(org.antlr.runtime.tree.CommonTree parent, AntlrTokens tokens, String data)
      add a text node
    • findChildrenWithType

      public static List<org.antlr.runtime.tree.CommonTree> findChildrenWithType(org.antlr.runtime.tree.CommonTree tree, int type)
      Find all children with the given type in the provided tree. Will only check 1st level children (i.e., this method is not recursive.)
      Parameters:
      tree -
      type -
      Returns:
      all children found with the given token type
    • findChildrenWithType

      public static List<org.antlr.runtime.tree.CommonTree> findChildrenWithType(org.antlr.runtime.tree.CommonTree tree, AntlrTokens tokens, String typeName)
      Find all children with the given type in the provided tree. Will only check 1st level children (i.e., this method is not recursive.)
      Parameters:
      tree -
      tokens -
      typeName -
      Returns:
      all children found with the given token type
    • findAllChildrenWithType

      public static List<org.antlr.runtime.tree.CommonTree> findAllChildrenWithType(org.antlr.runtime.tree.CommonTree tree, int type)
      Find all children and sub-children with the given type. This method will recursivly search the children of the given tree.
      Parameters:
      tree -
      type -
      Returns:
      the list of children found with the given type
    • findAllChildrenWithType

      public static List<org.antlr.runtime.tree.CommonTree> findAllChildrenWithType(org.antlr.runtime.tree.CommonTree tree, AntlrTokens tokens, String typeName)
      Find all children and sub-children with the given type. This method will recursively search the children of the given tree.
      Parameters:
      tree -
      tokens -
      typeName -
      Returns:
      the list of children found with the given type
    • findAllChildrenWithType

      public static List<org.antlr.runtime.tree.CommonTree> findAllChildrenWithType(org.antlr.runtime.tree.CommonTree tree, AntlrTokens tokens, String... typeNames)
      Find all children and sub-children with the given type. This method will recursively search the children of the given tree.
      Parameters:
      tree -
      tokens -
      typeName -
      Returns:
      the list of children found with the given type