def _match_sequence_variable(self, wildcard: Wildcard, transition: _Transition) -> Iterator[_State]:
min_count = wildcard.min_count
if len(self.subjects) < min_count:
return
matched_subject = []
for _ in range(min_count):
matched_subject.append(self.subjects.popleft())
while True:
if self.associative[-1] and wildcard.fixed_size:
assert min_count == 1, "Fixed wildcards with length != 1 are not supported."
if len(matched_subject) > 1:
wrapped = self.associative[-1](*matched_subject)
else:
wrapped = matched_subject[0]
else:
if len(matched_subject) == 0 and wildcard.optional is not None:
wrapped = wildcard.optional
else:
wrapped = tuple(matched_subject)
yield from self._check_transition(transition, wrapped, False)
if not self.subjects:
break
matched_subject.append(self.subjects.popleft())
self.subjects.extendleft(reversed(matched_subject))
评论列表
文章目录