R - the type of parsing results attached to leavesM - the type of diagnostic messages attached to stemsO - the type of obstructions to continuationpublic abstract class Action<R,M,O> extends Object
Search trees must not share nodes internally or externally. Some operations on search trees are transitions that may induce sharing between the input and output tree. If such a method is invoked and the output is used, then the input may not be used simultaneously anymore.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Action.BiContinuation<R,S,T,M,O>
Functional interface for binary continuations.
|
static interface |
Action.Continuation<R,S,M,O>
Functional interface for continuations.
|
static class |
Action.Trampoline<R,S,M,O> |
static class |
Action.Visitor<R,M,O> |
| Constructor and Description |
|---|
Action() |
| Modifier and Type | Method and Description |
|---|---|
abstract <S> Action<S,M,O> |
bind(Action.Continuation<? super R,S,M,O> cont)
Applies a monadic continuation to all leaves of this search tree
(transition operation).
|
static <R,M,O> Action<R,M,O> |
choice(Action<R,M,O>... alts)
Creates a search tree from a choice of alternative subtrees
|
static <R,M,O> Action<R,M,O> |
diagnosis(Action<R,M,O> body,
List<? extends M> msgs)
Creates a search tree with diagnostic message attached to the
root.
|
static <R,M,O> Action<R,M,O> |
diagnosis(Action<R,M,O> body,
M... msgs)
Creates a search tree with diagnostic message attached to the
root.
|
static <R,M,O> Action<R,M,O> |
fail()
Creates a search tree with no alternatives.
|
static <R,M,O> Action<R,M,O> |
fail(O obstruction)
Creates a search tree with no alternatives but an obstruction.
|
static <R,M,O> Action.Visitor<R,M,O> |
forEachObstruction(BiConsumer<O,ReverseList<M>> op) |
static <R,M,O> Action.Visitor<R,M,O> |
forEachResult(BiConsumer<R,ReverseList<M>> op) |
protected abstract int |
getLeafCount() |
abstract void |
host(Action.Visitor<? super R,M,O> v)
Performs a double dispatch to the appropriate method of a visitor.
|
abstract boolean |
isEmpty()
Checks whether this search tree is empty.
|
<S> Action<S,M,O> |
map(Function<? super R,? extends S> fun)
Applies a function to all leaves of this search tree (transition
operation).
|
static <R,M,O> Action<R,M,O> |
optional(Optional<? extends R> opt) |
static <R,S,M,O> Action<R,M,O> |
optional(Optional<S> opt,
Function<? super S,? extends R> convert) |
abstract <Q> Action<? extends R,M,Q> |
prune()
Simplifies this search tree by removing redundant choice nodes
and all obstructions (transition operation).
|
protected <Q> boolean |
pruneTo(List<? super Action<? extends R,M,Q>> alts)
Adds a pruned variant of this search subtree to a list of choice
alternatives.
|
static <R,M,O> Action<R,M,O> |
succeed(R result)
Creates a search tree with a single leaf.
|
static <R,M,O> Action<R,M,O> |
succeed(R result,
Success<?,M,O> recyclable)
Creates a search tree with a single leaf, possibly using a
recyclable leaf node.
|
protected abstract int getLeafCount()
public abstract <S> Action<S,M,O> bind(Action.Continuation<? super R,S,M,O> cont)
S - the output parsing result type of the continuationcont - the continuation to applypublic final <S> Action<S,M,O> map(Function<? super R,? extends S> fun)
S - the output parsing result type of the continuationfun - the function to applypublic abstract boolean isEmpty()
true iff this tree has no leavespublic abstract <Q> Action<? extends R,M,Q> prune()
Q - the new type of obstructionsprotected <Q> boolean pruneTo(List<? super Action<? extends R,M,Q>> alts)
Q - the new type of obstructionsalts - the list to add totrue iff this subtree has been simplified by
recursive pruningpublic static <R,M,O> Action<R,M,O> fail()
R - the type of parsing results attached to leavesM - the type of diagnostic messages attached to stemsO - the type of obstructions to continuationpublic static <R,M,O> Action<R,M,O> fail(O obstruction)
R - the type of parsing results attached to leavesM - the type of diagnostic messages attached to stemsO - the type of obstructions to continuationobstruction - the obstruction to fail withpublic static <R,M,O> Action<R,M,O> succeed(R result)
R - the type of parsing results attached to leavesM - the type of diagnostic messages attached to stemsO - the type of obstructions to continuationresult - the parsing resultpublic static <R,M,O> Action<R,M,O> succeed(R result, Success<?,M,O> recyclable)
R - the type of parsing results attached to leavesM - the type of diagnostic messages attached to stemsO - the type of obstructions to continuationresult - the parsing resultrecyclable - a recyclable leaf node, or null if
not availablerecyclable if available or new.@SafeVarargs public static <R,M,O> Action<R,M,O> diagnosis(Action<R,M,O> body, M... msgs)
R - the type of parsing results attached to leavesM - the type of diagnostic messages attached to stemsO - the type of obstructions to continuationbody - the search tree to attach messages tomsgs - an array of messages to attachIllegalArgumentException - if body == null or msgs == nullpublic static <R,M,O> Action<R,M,O> diagnosis(Action<R,M,O> body, List<? extends M> msgs)
R - the type of parsing results attached to leavesM - the type of diagnostic messages attached to stemsO - the type of obstructions to continuationbody - the search tree to attach messages tomsgs - a list of messages to attachIllegalArgumentException - if body == null or msgs == null@SafeVarargs public static <R,M,O> Action<R,M,O> choice(Action<R,M,O>... alts)
R - the type of parsing results attached to leavesM - the type of diagnostic messages attached to stemsO - the type of obstructions to continuationalts - an array of alternative subtreesIllegalArgumentException - if alts == nullpublic static <R,S,M,O> Action<R,M,O> optional(Optional<S> opt, Function<? super S,? extends R> convert)
public abstract void host(Action.Visitor<? super R,M,O> v)
v - the visitorpublic static <R,M,O> Action.Visitor<R,M,O> forEachResult(BiConsumer<R,ReverseList<M>> op)
public static <R,M,O> Action.Visitor<R,M,O> forEachObstruction(BiConsumer<O,ReverseList<M>> op)
see also the complete user documentation .