Browse Source

BUGFIX: tree-less transformer may hang for empty values (Issue #49)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan 7 years ago
parent
commit
fbeb0e6e59
1 changed files with 7 additions and 3 deletions
  1. +7
    -3
      lark/parsers/lalr_parser.py

+ 7
- 3
lark/parsers/lalr_parser.py View File

@@ -7,6 +7,10 @@ from ..common import ParseError, UnexpectedToken

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"
@@ -56,7 +60,7 @@ class _Parser:
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
@@ -85,9 +89,9 @@ class _Parser:
_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




Loading…
Cancel
Save