Skip to content

Commit

Permalink
RegExp fix: already try to find longest match, but not only the last …
Browse files Browse the repository at this point in the history
…(prev_stack) one because that can't always terminate (can_terminate)
  • Loading branch information
koenvossen committed Jun 18, 2020
1 parent 183e0be commit 5882aca
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions kloppy/domain/services/matchers/pattern/regexp/regexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def match(

stack: List[Explorer[Tok, Out]] = [Explorer(self, _Initial(), tuple())]

prev_stack = None
stacks = []
for token in seq:
stack = list(
self._de_duplicate(
Expand All @@ -616,10 +616,14 @@ def match(
if not stack:
break

prev_stack = stack
stacks.append(stack)

if not consume_all and prev_stack:
stack = [s for s in prev_stack if s.can_terminate()]
if not consume_all and stacks:
stacks.reverse()
for stack in stacks:
stack = [s for s in stack if s.can_terminate()]
if stack:
break

terminal = list(
self._de_duplicate(
Expand Down

0 comments on commit 5882aca

Please sign in to comment.