Package eu.bandm.tools.ramus.ogma
Class Action<R,M,O>
java.lang.Object
eu.bandm.tools.ramus.ogma.Action<R,M,O>
- Type Parameters:
R- the type of parsing results attached to leavesM- the type of diagnostic messages attached to stemsO- the type of obstructions to continuation
- Direct Known Subclasses:
Action.Success
Base class of the parsing search-tree monad.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for binary continuations.static interfaceFunctional interface for search-tree continuations.static final classLeaf node class of the parsing search-tree monad.static classVisitor base class for search trees. -
Method Summary
Modifier and TypeMethodDescriptionbind(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> Creates a search tree from a choice of alternative subtreesstatic <R,M, O> Action <R, M, O> Creates a search tree from a choice of alternative subtreesstatic <R,M, O> Action <R, M, O> Creates a search tree with diagnostic message attached to the root.static <R,M, O> Action <R, M, O> 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,S, M, O>
Action.BiContinuation<R, S, R, M, O> first()Returns a binary continuation that purely selects the first argument.voidforEachObstruction(BiConsumer<O, List<M>> op) Visits all obstructions.voidforEachResult(BiConsumer<R, List<M>> op) Visits all leaves.Collection<Map.Entry<R, List<M>>> Returns a collection of all leaves, each together with the messages accumulated along the respective path.abstract voidhost(Action.Visitor<? super R, M, O> v) Performs a double dispatch to the appropriate method of a visitor.abstract booleanisEmpty()Checks whether this search tree is empty.Applies a function to all leaves of this search tree (transition operation).prune()Simplifies this search tree by removing redundant choice nodes and all obstructions (transition operation).static <R,S, M, O>
Action.BiContinuation<R, S, S, M, O> second()Returns a binary continuation that purely selects the second argument.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, @Opt Action.Success<?, M, O> recyclable) Creates a search tree with a single leaf, possibly using a recyclable leaf node.static <R,M, O> Action.Visitor <R, M, O> visitEachObstruction(BiConsumer<O, List<M>> op) Creates a visitor that recognizes obstructions.static <R,M, O> Action.Visitor <R, M, O> visitEachResult(BiConsumer<R, List<M>> op) Creates a visitor that recognizes leaves.
-
Method Details
-
bind
Applies a monadic continuation to all leaves of this search tree (transition operation).- Type Parameters:
S- the output parsing result type of the continuation- Parameters:
cont- the continuation to apply- Returns:
- an updated search tree
- Throws:
NullPointerException- ifcontis null
-
map
Applies a function to all leaves of this search tree (transition operation).- Type Parameters:
S- the output parsing result type of the continuation- Parameters:
fun- the function to apply- Returns:
- an updated search tree
- Throws:
NullPointerException- iffunis null
-
isEmpty
public abstract boolean isEmpty()Checks whether this search tree is empty.- Returns:
trueif this tree has no leaves,falseif some success leaves are found
-
prune
Simplifies this search tree by removing redundant choice nodes and all obstructions (transition operation).- Type Parameters:
Q- the new type of obstructions- Returns:
- a simplified search tree without nested or unary choice nodes
-
fail
Creates a search tree with no alternatives.- Type Parameters:
R- the type of parsing results attached to leavesM- the type of diagnostic messages attached to stemsO- the type of obstructions to continuation- Returns:
- a search tree with no alternatives
-
fail
Creates a search tree with no alternatives but an obstruction.- Type Parameters:
R- the type of parsing results attached to leavesM- the type of diagnostic messages attached to stemsO- the type of obstructions to continuation- Parameters:
obstruction- the obstruction to fail with- Returns:
- a search tree with no alternatives
-
succeed
Creates a search tree with a single leaf.- Type Parameters:
R- the type of parsing results attached to leavesM- the type of diagnostic messages attached to stemsO- the type of obstructions to continuation- Parameters:
result- the parsing result- Returns:
- a tree with a single leaf holding the given result
-
succeed
Creates a search tree with a single leaf, possibly using a recyclable leaf node.- Type Parameters:
R- the type of parsing results attached to leavesM- the type of diagnostic messages attached to stemsO- the type of obstructions to continuation- Parameters:
result- the parsing resultrecyclable- a recyclable leaf node, ornullif not available- Returns:
- a leaf node with a newly computed parsing result; either
recyclableif available ornew.
-
diagnosis
Creates a search tree with diagnostic message attached to the root.- Type Parameters:
R- the type of parsing results attached to leavesM- the type of diagnostic messages attached to stemsO- the type of obstructions to continuation- Parameters:
body- the search tree to attach messages tomsgs- an array of messages to attach- Returns:
- a search tree with the messages attached to the body
- Throws:
NullPointerException- ifbodyormsgsis null
-
diagnosis
Creates a search tree with diagnostic message attached to the root.- Type Parameters:
R- the type of parsing results attached to leavesM- the type of diagnostic messages attached to stemsO- the type of obstructions to continuation- Parameters:
body- the search tree to attach messages tomsgs- a list of messages to attach- Returns:
- a search tree with the messages attached to the body
- Throws:
NullPointerException- ifbodyormsgsis null
-
choice
Creates a search tree from a choice of alternative subtrees- Type Parameters:
R- the type of parsing results attached to leavesM- the type of diagnostic messages attached to stemsO- the type of obstructions to continuation- Parameters:
alts- an array of alternative subtrees- Returns:
- a search tree with a choice root and the given alternatives
- Throws:
NullPointerException- ifaltsis null
-
choice
Creates a search tree from a choice of alternative subtrees- Type Parameters:
R- the type of parsing results attached to leavesM- the type of diagnostic messages attached to stemsO- the type of obstructions to continuation- Parameters:
alts- a list of alternative subtrees- Returns:
- a search tree with a choice root and the given alternatives
- Throws:
NullPointerException- ifaltsis null
-
first
Returns a binary continuation that purely selects the first argument.- Type Parameters:
R- the first input type of parsing resultsS- the second input type of parsing resultsM- the type of diagnostic messagesO- the type of obstructions to continuation- Returns:
- a binary continuation that purely selects the first argument
-
second
Returns a binary continuation that purely selects the second argument.- Type Parameters:
R- the first input type of parsing resultsS- the second input type of parsing resultsM- the type of diagnostic messagesO- the type of obstructions to continuation- Returns:
- a binary continuation that purely selects the second argument
-
host
Performs a double dispatch to the appropriate method of a visitor.- Parameters:
v- the visitor
-
visitEachResult
Creates a visitor that recognizes leaves.- Type Parameters:
R- the type of parsing results attached to leavesM- the type of diagnostic messages attached to stemsO- the type of obstructions to continuation- Parameters:
op- a consumer for pairs of a result at a leaf, and the messages accumulated along the path- Returns:
- a visitor that invokes
opfor all leaves - Throws:
NullPointerException- ifopis null
-
forEachResult
Visits all leaves.- Parameters:
op- a consumer for pairs of a result at a leaf, and the messages accumulated along the path- Throws:
NullPointerException- ifopis null- See Also:
-
getResults
Returns a collection of all leaves, each together with the messages accumulated along the respective path.- Returns:
- a collection of map entries with the leaf result as the key and the messages accumulated on the path as the value
-
visitEachObstruction
Creates a visitor that recognizes obstructions.- Type Parameters:
R- the type of parsing results attached to leavesM- the type of diagnostic messages attached to stemsO- the type of obstructions to continuation- Parameters:
op- a consumer for pairs of an obstruction, and the messages accumulates along the path- Returns:
- a visitor that invokes
opfor all obstructions - Throws:
NullPointerException- ifopis null
-
forEachObstruction
Visits all obstructions.- Parameters:
op- a consumer for pairs of an obstruction, and the messages accumulates along the path- Throws:
NullPointerException- ifopis null- See Also:
-