Skip to content

Commit

Permalink
Fix #1345 by not calling the callbacks from InteractiveParser.accepts
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaIng committed Sep 28, 2023
1 parent 05eb59b commit 70bd307
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lark/parsers/lalr_interactive_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,14 @@ def choices(self):
def accepts(self):
"""Returns the set of possible tokens that will advance the parser into a new valid state."""
accepts = set()
conf_no_callbacks = copy(self.parser_state.parse_conf)
# We don't want to call callbacks here since those might have arbitrary side effects
# and are unnecessarily slow.
conf_no_callbacks.callbacks = {}
for t in self.choices():
if t.isupper(): # is terminal?
new_cursor = copy(self)
new_cursor.parser_state.parse_conf = conf_no_callbacks
try:
new_cursor.feed_token(self.lexer_thread._Token(t, ''))
except UnexpectedToken:
Expand Down
2 changes: 1 addition & 1 deletion lark/parsers/lalr_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def feed_token(self, token, is_end=False):
else:
s = []

value = callbacks[rule](s)
value = callbacks[rule](s) if callbacks else s

_action, new_state = states[state_stack[-1]][rule.origin.name]
assert _action is Shift
Expand Down

0 comments on commit 70bd307

Please sign in to comment.