pattern: (a*a)|c
Let's trace the execution:
Alternation(alternatives=[ Group(regex=Concatenation( items=[ Quantifier(atom=Character(value='a'), min_count=0, max_count=None, greedy=True), Character(value='b')] ), name=None, capturing=True), Character(value='c')])
This is the AST for the pattern.
Input String: aaa
How would the pattern match this string?
-
In
matcher.match()method, we will ask the generatematch_nodeto yield its values by iterating over the loop. -
In
match_nodemethod, we will first callmatch_alternationand yield tomatchmethod:yield from self.match_alternation(node, pos)- By saying
yield from, we are saying that for each value yielded from the match_alternation method, return that value tomatch().
- By saying
-
In
match_alternationmethod, we iterate over each alternatives and then callmatch_nodeon that alternative & yield it. Here, the first alternative is the Group. In the Group, we again yield a value.