public final class ParseTreeUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <V,C extends Collection<Node<V>>> |
collectNodes(List<Node<V>> parents,
Predicate<Node<V>> predicate,
C collection)
Collects all nodes underneath the given parents for which the given predicate evaluates to true.
|
static <V,C extends Collection<Node<V>>> |
collectNodes(Node<V> parent,
Predicate<Node<V>> predicate,
C collection)
Collects all nodes underneath the given parent for which the given predicate evaluates to true.
|
static <V,C extends Collection<Node<V>>> |
collectNodesByPath(List<Node<V>> parents,
String path,
C collection)
Collects all nodes underneath the given parents that match the given path.
|
static <V,C extends Collection<Node<V>>> |
collectNodesByPath(Node<V> parent,
String path,
C collection)
Collects all nodes underneath the given parent that match the given path.
|
static <V> Node<V> |
findLastNode(List<Node<V>> parents,
Predicate<Node<V>> predicate)
Returns the last node underneath the given parents for which the given predicate evaluates to true.
|
static <V> Node<V> |
findLastNode(Node<V> parent,
Predicate<Node<V>> predicate)
Returns the last node underneath the given parent for which the given predicate evaluates to true.
|
static <V> Node<V> |
findNode(List<Node<V>> parents,
Predicate<Node<V>> predicate)
Returns the first node underneath the given parents for which the given predicate evaluates to true.
|
static <V> Node<V> |
findNode(Node<V> parent,
Predicate<Node<V>> predicate)
Returns the first node underneath the given parent for which the given predicate evaluates to true.
|
static <V> Node<V> |
findNodeByLabel(List<Node<V>> parents,
String labelPrefix)
Returns the first node underneath the given parents which matches the given label prefix.
|
static <V> Node<V> |
findNodeByLabel(Node<V> parent,
String labelPrefix)
Returns the first node underneath the given parent for which matches the given label prefix.
|
static <V> Node<V> |
findNodeByPath(List<Node<V>> parents,
String path)
Returns the node underneath the given parents that matches the given path.
|
static <V> Node<V> |
findNodeByPath(Node<V> parent,
String path)
Returns the parse tree node underneath the given parent that matches the given path.
|
static String |
getNodeText(Node<?> node,
InputBuffer inputBuffer)
Returns the input text matched by the given node, with error correction.
|
static <V> String |
printNodeTree(ParsingResult<V> parsingResult)
Creates a readable string represenation of the parse tree in the given
ParsingResult object. |
static <V> String |
printNodeTree(ParsingResult<V> parsingResult,
Predicate<Node<V>> nodeFilter,
Predicate<Node<V>> subTreeFilter)
Creates a readable string represenation of the parse tree in thee given
ParsingResult object. |
public static <V> Node<V> findNodeByPath(Node<V> parent, String path)
Returns the parse tree node underneath the given parent that matches the given path.
The path is a '/' separated list of node label prefixes describing the ancestor chain of the node to look for relative to the given parent node. If there are several nodes that match the given path the method returns the first one unless the respective path segments has the special prefix "last:". In this case the last matching node is returned.
Example: "per/last:so/fix" will return the first node, whose label starts with "fix" under the last node, whose label starts with "so" under the first node, whose label starts with "per".
If parent is null or no node is found the method returns null.parent
- the parent Nodepath
- the path to the Node being searched forpublic static <V> Node<V> findNodeByPath(List<Node<V>> parents, String path)
findNodeByPath(org.parboiled.Node, String)
)} for a description of the path argument.
If the given collections of parents is null or empty or no node is found the method returns null.parents
- the parent Nodes to look throughpath
- the path to the Node being searched forpublic static <V,C extends Collection<Node<V>>> C collectNodesByPath(Node<V> parent, String path, C collection)
parent
- the parent Nodepath
- the path to the Nodes being searched forcollection
- the collection to collect the found Nodes intopublic static <V,C extends Collection<Node<V>>> C collectNodesByPath(List<Node<V>> parents, String path, C collection)
parents
- the parent Nodes to look throughpath
- the path to the Nodes being searched forcollection
- the collection to collect the found Nodes intopublic static <V> Node<V> findNode(Node<V> parent, Predicate<Node<V>> predicate)
parent
- the parent Nodepredicate
- the predicatepublic static <V> Node<V> findNode(List<Node<V>> parents, Predicate<Node<V>> predicate)
parents
- the parent Nodes to look throughpredicate
- the predicatepublic static <V> Node<V> findNodeByLabel(Node<V> parent, String labelPrefix)
parent
- the parent nodelabelPrefix
- the label prefix to look forpublic static <V> Node<V> findNodeByLabel(List<Node<V>> parents, String labelPrefix)
parents
- the parent Nodes to look throughlabelPrefix
- the label prefix to look forpublic static <V> Node<V> findLastNode(Node<V> parent, Predicate<Node<V>> predicate)
parent
- the parent Nodepredicate
- the predicatepublic static <V> Node<V> findLastNode(List<Node<V>> parents, Predicate<Node<V>> predicate)
parents
- the parent Nodes to look throughpredicate
- the predicatepublic static <V,C extends Collection<Node<V>>> C collectNodes(Node<V> parent, Predicate<Node<V>> predicate, C collection)
parent
- the parent Nodepredicate
- the predicatecollection
- the collection to collect the found Nodes intopublic static String getNodeText(Node<?> node, InputBuffer inputBuffer)
node
- the nodeinputBuffer
- the underlying inputBufferpublic static <V,C extends Collection<Node<V>>> C collectNodes(List<Node<V>> parents, Predicate<Node<V>> predicate, C collection)
parents
- the parent Nodes to look throughpredicate
- the predicatecollection
- the collection to collect the found Nodes intopublic static <V> String printNodeTree(ParsingResult<V> parsingResult)
ParsingResult
object.parsingResult
- the parsing result containing the parse treepublic static <V> String printNodeTree(ParsingResult<V> parsingResult, Predicate<Node<V>> nodeFilter, Predicate<Node<V>> subTreeFilter)
ParsingResult
object.
The given filter predicate determines whether a particular node (incl. its subtree) is printed or not.parsingResult
- the parsing result containing the parse treenodeFilter
- the predicate selecting the nodes to printsubTreeFilter
- the predicate determining whether to descend into a given nodes subtree or notCopyright © 2018. All rights reserved.