lark-parser / lark

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
MIT License
4.64k stars 397 forks source link

Fix #1345 by not calling the callbacks from InteractiveParser.accepts #1346

Closed MegaIng closed 9 months ago

MegaIng commented 9 months ago

This also has the nice benefit of making accepts faster since it does less work. Technically this is an option that an end user can access on their instance of InteractiveParser, so I added a bit of documentation.

erezsh commented 9 months ago

I wonder if instead of having to add a new parameter on all these methods, we can instead clear the callbacks on the copy method which accepts() uses. Like new_cursor = self.copy(callbacks = {}).

Then all we need is to change in the parser is value = callbacks[rule](s) if callbacks else s

It's a bit more implicit, but it feels cleaner to me. What do you think?

MegaIng commented 9 months ago

We are currently avoiding creating a copy of the ParserConf object since it's semantically immutable. So we have to either:

erezsh commented 9 months ago

An alternative implementation has been merged.