|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.parboiled.support.ParseTreeUtils
public final class ParseTreeUtils
General utility methods for operating on parse trees.
Method Summary | ||
---|---|---|
static
|
collectNodes(java.util.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
|
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
|
collectNodesByPath(java.util.List<Node<V>> parents,
java.lang.String path,
C collection)
Collects all nodes underneath the given parents that match the given path. |
|
static
|
collectNodesByPath(Node<V> parent,
java.lang.String path,
C collection)
Collects all nodes underneath the given parent that match the given path. |
|
static
|
findLastNode(java.util.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
|
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
|
findNode(java.util.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
|
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
|
findNodeByLabel(java.util.List<Node<V>> parents,
java.lang.String labelPrefix)
Returns the first node underneath the given parents which matches the given label prefix. |
|
static
|
findNodeByLabel(Node<V> parent,
java.lang.String labelPrefix)
Returns the first node underneath the given parent for which matches the given label prefix. |
|
static
|
findNodeByPath(java.util.List<Node<V>> parents,
java.lang.String path)
Returns the node underneath the given parents that matches the given path. |
|
static
|
findNodeByPath(Node<V> parent,
java.lang.String path)
Returns the parse tree node underneath the given parent that matches the given path. |
|
static java.lang.String |
getNodeText(Node<?> node,
InputBuffer inputBuffer)
Returns the input text matched by the given node, with error correction. |
|
static java.lang.String |
getRawNodeText(Node<?> node,
InputBuffer inputBuffer)
Returns the raw input text matched by the given node, without error correction. |
|
static
|
printNodeTree(ParsingResult<V> parsingResult)
Creates a readable string represenation of the parse tree in the given ParsingResult object. |
|
static
|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <V> Node<V> findNodeByPath(Node<V> parent, java.lang.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 for
public static <V> Node<V> findNodeByPath(java.util.List<Node<V>> parents, java.lang.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 for
public static <V,C extends java.util.Collection<Node<V>>> C collectNodesByPath(Node<V> parent, java.lang.String path, C collection)
parent
- the parent Nodepath
- the path to the Nodes being searched forcollection
- the collection to collect the found Nodes into
public static <V,C extends java.util.Collection<Node<V>>> C collectNodesByPath(java.util.List<Node<V>> parents, java.lang.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 into
public static <V> Node<V> findNode(Node<V> parent, Predicate<Node<V>> predicate)
parent
- the parent Nodepredicate
- the predicate
public static <V> Node<V> findNode(java.util.List<Node<V>> parents, Predicate<Node<V>> predicate)
parents
- the parent Nodes to look throughpredicate
- the predicate
public static <V> Node<V> findNodeByLabel(Node<V> parent, java.lang.String labelPrefix)
parent
- the parent nodelabelPrefix
- the label prefix to look for
public static <V> Node<V> findNodeByLabel(java.util.List<Node<V>> parents, java.lang.String labelPrefix)
parents
- the parent Nodes to look throughlabelPrefix
- the label prefix to look for
public static <V> Node<V> findLastNode(Node<V> parent, Predicate<Node<V>> predicate)
parent
- the parent Nodepredicate
- the predicate
public static <V> Node<V> findLastNode(java.util.List<Node<V>> parents, Predicate<Node<V>> predicate)
parents
- the parent Nodes to look throughpredicate
- the predicate
public static <V,C extends java.util.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 into
public static java.lang.String getNodeText(Node<?> node, InputBuffer inputBuffer)
node
- the nodeinputBuffer
- the underlying inputBuffer
public static <V,C extends java.util.Collection<Node<V>>> C collectNodes(java.util.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 into
public static java.lang.String getRawNodeText(Node<?> node, InputBuffer inputBuffer)
node
- the nodeinputBuffer
- the underlying inputBuffer
public static <V> java.lang.String printNodeTree(ParsingResult<V> parsingResult)
ParsingResult
object.
parsingResult
- the parsing result containing the parse tree
public static <V> java.lang.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 not
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |