Package eu.bandm.tools.ramus.runtime2
Class Action<R,M,O>
java.lang.Object
eu.bandm.tools.ramus.runtime2.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
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
Modifier and TypeClassDescriptionstatic interface
Functional interface for binary continuations.static interface
Functional interface for continuations.static class
static class
-
Constructor Summary
-
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 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,
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
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.Applies a function to all leaves of this search tree (transition operation).static <R,
M, O> Action<R, M, O> static <R,
S, M, O> Action<R, M, O> prune()
Simplifies this search tree by removing redundant choice nodes and all obstructions (transition operation).protected <Q> boolean
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> Creates a search tree with a single leaf, possibly using a recyclable leaf node.
-
Constructor Details
-
Action
public Action()
-
-
Method Details
-
getLeafCount
protected abstract int getLeafCount() -
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
-
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
-
isEmpty
public abstract boolean isEmpty()Checks whether this search tree is empty.- Returns:
true
iff this tree has no leaves
-
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
-
pruneTo
Adds a pruned variant of this search subtree to a list of choice alternatives.- Type Parameters:
Q
- the new type of obstructions- Parameters:
alts
- the list to add to- Returns:
true
iff this subtree has been simplified by recursive pruning
-
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, ornull
if not available- Returns:
- a leaf node with a newly computed parsing result;
either
recyclable
if 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:
IllegalArgumentException
- ifbody == null
ormsgs == 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:
IllegalArgumentException
- ifbody == null
ormsgs == 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:
IllegalArgumentException
- ifalts == null
-
optional
-
optional
-
host
Performs a double dispatch to the appropriate method of a visitor.- Parameters:
v
- the visitor
-
forEachResult
-
forEachObstruction
-