Skip to content

Commit

Permalink
BUGFIX: tree-less transformer may hang for empty values (Issue #49)
Browse files Browse the repository at this point in the history
  • Loading branch information
erezsh committed Dec 14, 2017
1 parent 5748920 commit fbeb0e6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lark/parsers/lalr_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

from .lalr_analysis import LALR_Analyzer, ACTION_SHIFT

class FinalReduce:
def __init__(self, value):
self.value = value

class Parser:
def __init__(self, parser_conf):
assert all(o is None or o.priority is None for n,x,a,o in parser_conf.rules), "LALR doesn't yet support prioritization"
Expand Down Expand Up @@ -56,7 +60,7 @@ def reduce(rule, size, end=False):
res = self.callbacks[rule](s)

if end and len(state_stack) == 1 and rule.origin == self.start_symbol:
return res
return FinalReduce(res)

_action, new_state = get_action(rule.origin)
assert _action == ACTION_SHIFT
Expand Down Expand Up @@ -85,9 +89,9 @@ def reduce(rule, size, end=False):
_action, rule = get_action('$end')
assert _action == 'reduce'
res = reduce(*rule, end=True)
if res:
if isinstance(res, FinalReduce):
assert state_stack == [self.init_state] and not value_stack, len(state_stack)
return res
return res.value



0 comments on commit fbeb0e6

Please sign in to comment.