Matches any slice of a sequence.
Inherits From: Star
, Pattern
oryx.experimental.matching.matcher.Segment(
name: Optional[str],
accumulate: Sequence[str] = (),
greedy: bool = False,
plus: bool = False
)
Attributes |
name
|
a str name to bind the result of the segment match. If name is
None , a match produces no binding.
|
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 Segment greedily matches a
sequence. A greedy Segment will try to match slices starting from the
largest possible and then trying smaller ones. A non-greedy Segment will
match slices starting from the smallest possible.
Default: False .
|
plus
|
a bool , if True requires matches of length one or more and if
False allows zero-length matches.
Default: False
|
pattern
|
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
|