public final class Variable<A> extends Pattern<A> implements Extractor<A>
A pattern variable is deterministic, matches any object and binds itself.
Constructor and Description |
---|
Variable()
Creates a new anonymous variable.
|
Variable(String name)
Creates a new named variable.
|
Modifier and Type | Method and Description |
---|---|
boolean |
binds(Variable<?> var)
Checks whether a variable is bound by this pattern.
|
void |
clear(boolean recursively)
Disposes of all internal state related to results and
nondeterminism.
|
Variable<A> |
clone()
Makes a matching-state copy if this pattern.
|
protected void |
compileCut(eu.bandm.tools.paisley.CompilationContext context) |
protected void |
compileCut(eu.bandm.tools.paisley.CompilationContext context,
boolean recursively) |
protected void |
compileMatchAgain(eu.bandm.tools.paisley.CompilationContext context) |
String |
getName()
Returns the name of this variable.
|
A |
getValue()
Returns the current value bound to this variable.
|
<B> Motif<A,B> |
lambda(Pattern<B> body) |
boolean |
match(A target)
Attempts to match this pattern against a given object.
|
Pattern<A> |
plus(Pattern<? super A> root)
Returns the "plus" variant of the Kleene fixpoint of a pattern
as a function of this variable.
|
boolean |
preserves(Variable<?> var)
Checks whether a variable is preserved by this pattern,
unconditionally.
|
boolean |
preserves(Variable<?> var,
boolean success)
Checks whether a variable is preserved by this pattern,
conditionally on success or failure.
|
Pattern<A> |
star(Pattern<? super A> root)
Returns the "star" variant of the Kleene fixpoint of a pattern
as a function of this variable.
|
String |
toString() |
all, all, all, all, all, and, andThen, andThen, any, any, aside, both, clear, compareTo, compile, compileClear, compileClear, compileIsDeterministic, compileMatch, compileSubPattern, compileThis, compileUpTo, cut, cut, DEBUG, either, enPassant, eq, eqNull, equal, filter, flatten, forInstancesOf, isDeterministic, limit, main, matchAgain, matchOnce, matchVar, narrow, neq, neqNull, newAll, noMatch, none, or, orElse, orElse, repeat, some, some, some, some, someMatch, startCompile, test, transform, uniquely, variable, variable
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
bind, eagerBindings, lazyBindings
public Variable()
public Variable(String name)
name
- the variable name.public String getName()
null
if this
variable is anonymous.public A getValue()
null
. It is set to a meaningful
value by a successful match with a pattern that guarantees to
bind the variable. It may be set to an unspecified value by a
match with a pattern that does not guarantee to preserve the
variable.getValue
in interface Extractor<A>
Pattern.binds(eu.bandm.tools.paisley.Variable<?>)
,
Pattern.preserves(eu.bandm.tools.paisley.Variable<?>, boolean)
public void clear(boolean recursively)
The default implementation does nothing. This implementation resets the variable value to
null
.
public boolean match(A target)
target
.match
in class Pattern<A>
target
- the object to match againsttrue
Pattern.binds(Variable)
,
Pattern.preserves(Variable, boolean)
public boolean binds(Variable<?> var)
Pattern
The default implementation returns false
.
public boolean preserves(Variable<?> var, boolean success)
Pattern
The default implementation returns false
.
public boolean preserves(Variable<?> var)
Pattern
The default implementation returns false
.
public Variable<A> clone()
Pattern
Subclasses must override this method if necessary to honour the following rules for all transitively reachable patterns:
Variable
must
be shared. This implies that clone()
must
return this
.Pattern.match(A)
, Pattern.matchAgain()
, Pattern.cut()
or Pattern.clear()
) must be duplicated. If matching state changes are
effected by modification of other objects, these must be
duplicated. In summary, matching operations on this pattern and
its copy must not interfere, with the exception of variable
bindings.this
.public Pattern<A> plus(Pattern<? super A> root)
Conceptually, x.star(p)
is equivalent to the pattern
arising from p.clone()
by substituting x.star(p)
for x
. Note that this cannot be used naively for
implementation, since the ensuing recursive substitution would
not terminate. The actual implementation guarantees to produce
only as many new subpatterns as dynamically necessary.
public Pattern<A> star(Pattern<? super A> root)
Conceptually, x.star(p)
is equivalent to either(x, x.plus(p))
.
Pattern.either(Pattern, Pattern)
,
plus(Pattern)
protected void compileMatchAgain(eu.bandm.tools.paisley.CompilationContext context)
compileMatchAgain
in class Pattern<A>
protected void compileCut(eu.bandm.tools.paisley.CompilationContext context)
compileCut
in class Pattern<A>
protected void compileCut(eu.bandm.tools.paisley.CompilationContext context, boolean recursively)
compileCut
in class Pattern<A>
see also the complete user documentation .