A pattern for repeated sub-patterns inside of a sequence.
Inherits From: Star
, Pattern
oryx.experimental.matching.matcher.Plus(
pattern: Any,
name: Optional[str] = None,
accumulate: Sequence[str] = (),
greedy: bool = False
)
Attributes |
pattern
|
an object that will be matched against elements of a sequence.
|
name
|
an optional str name to bind the result of the star match.
|
accumulate
|
a sequence of str names corresponding to Var s in pattern
that will be accumulated into a sequence instead of having to match across
the elements of the sequence.
|
greedy
|
a bool that sets whether or not the Plus greedily matches a
sequence. A greedy Plus will try to match slices starting from the
largest possible and then trying smaller ones. A non-greedy Plus will
match slices starting from the smallest possible.
Default: False .
|
plus
|
Dataclass field
|
Methods
accumulate_match
View source
accumulate_match(
expr: Expr,
bindings: oryx.experimental.matching.jax_rewrite.Bindings
,
succeed: oryx.experimental.matching.jax_rewrite.Continuation
) -> oryx.experimental.matching.jax_rewrite.Success
Matches each element of a sequence to this Star
's pattern.
Iteratively matches each element of expr
with self.pattern
. For any
created as the result of each match, they are accumulated if the names
are in the Star
pattern's accumulate
property. If not, the bindings need
to match over all elemnets of expr
.
Args |
expr
|
An expression to match.
|
bindings
|
A dictionary mapping string names to values representing the
results of previous matches.
|
succeed
|
A function that when passed in bindings returns a generator
over results.
|
Yields |
The results of the succeed continuation function, augmented with
bindings corresponding to matches made over the course of the accumulate
match.
|
accumulate_value
View source
accumulate_value(
bindings: oryx.experimental.matching.jax_rewrite.Bindings
,
name: str,
value: Any
) -> oryx.experimental.matching.jax_rewrite.Bindings
bind
View source
bind(
bindings: oryx.experimental.matching.jax_rewrite.Bindings
,
value: Any
) -> oryx.experimental.matching.jax_rewrite.Bindings
match
View source
match(
expr: Expr,
bindings: oryx.experimental.matching.jax_rewrite.Bindings
,
succeed: StarContinuation
) -> oryx.experimental.matching.jax_rewrite.Success
Matches the Star
pattern against an expression.
Constructs all splits of the expression and performs an accumulate_match
on each of the left halves. The right half is matched using sequence
matching.
Args |
expr
|
An expression to match.
|
bindings
|
A dictionary mapping string names to values representing the
results of previous matches.
|
succeed
|
A function that when passed in bindings returns a generator
over results.
|
Yields |
The results of the succeed continuation function, augmented with
bindings corresponding to matches made over the course of the Star match.
|
__eq__
__eq__(
other
)
Class Variables |
accumulate
|
()
|
greedy
|
False
|
name
|
None
|
plus
|
False
|