oryx.experimental.matching.matcher.Segment

Matches any slice of a sequence.

Inherits From: Star, Pattern

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 Vars 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

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

bind

View source

match

View source

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__

accumulate ()
greedy False
name None
plus False