Browse Source

Bugfix: Infinite loop on mishandled $END token in on_error (Issue #656)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.10.0
Erez Sh 4 years ago
parent
commit
0c47b981fc
2 changed files with 14 additions and 0 deletions
  1. +3
    -0
      lark/lark.py
  2. +11
    -0
      lark/parsers/lalr_puppet.py

+ 3
- 0
lark/lark.py View File

@@ -413,6 +413,9 @@ class Lark(Serialize):
try:
return e.puppet.resume_parse()
except UnexpectedToken as e2:
if e.token.type == e2.token.type == '$END' and e.puppet == e2.puppet:
# Prevent infinite loop
raise e2
e = e2




+ 11
- 0
lark/parsers/lalr_puppet.py View File

@@ -68,6 +68,17 @@ class ParserPuppet(object):
self._set_state,
)

def __eq__(self, other):
if not isinstance(other, ParserPuppet):
return False

return (
self._state_stack == other._state_stack and
self._value_stack == other._value_stack and
self._stream == other._stream and
self._start == other._start
)

def pretty(self):
out = ["Puppet choices:"]
for k, v in self.choices().items():


Loading…
Cancel
Save