matchpy.matching.one_to_one module¶
-
match
(subject: matchpy.expressions.expressions.Expression, pattern: matchpy.expressions.expressions.Pattern) → Iterator[matchpy.expressions.substitution.Substitution]¶ Tries to match the given pattern to the given subject.
Yields each match in form of a substitution.
Parameters: - subject – An subject to match.
- pattern – The pattern to match.
Yields: All possible match substitutions.
Raises: ValueError
– If the subject is not constant.
-
match_anywhere
(subject: matchpy.expressions.expressions.Expression, pattern: matchpy.expressions.expressions.Pattern) → Iterator[Tuple[matchpy.expressions.substitution.Substitution, Tuple[int, ...]]]¶ Tries to match the given pattern to the any subexpression of the given subject.
Yields each match in form of a substitution and a position tuple. The position is a tuple of indices, e.g. the empty tuple refers to the subject itself,
(0, )
refers to the first child (operand) of the subject,(0, 0)
to the first child of the first child etc.Parameters: - subject – An subject to match.
- pattern – The pattern to match.
Yields: All possible substitution and position pairs.
Raises: ValueError
– If the subject is not constant.