Standalone parser cannot be used more than once
See original GitHub issueThat is, Lark_StandAlone().parse()
cannot be called more than once on different inputs. This is from master. I found two reasons for it:
rule.alias
is overwritten permanently inParseTreeBuilder.create_callback()
, causing errors elsewhere on subsequent runs.- In Python 3, the
wrapper_chain = filter(...)
inParseTreeBuilder._init_builders()
creates a filter object that can only be consumed once.
Now, within an already-generated standalone parser, I’ve found it suffices to make the following edits:
Rule.__init__()
: addself.cb_name = None
- Line 2 of
Lark_StandAlone.__init__()
: change tocallbacks = {rule: getattr(callback, rule.cb_name or rule.origin, None) for rule in RULES.values()}
- Line 19 of
ParseTreeBuilder.create_callback()
: change torule.cb_name = internal_callback_name
- Line 6 of
ParseTreeBuilder._init_builders()
: change towrapper_chain = list(filter(None, [
However, when trying to edit these into Lark itself (so that lark.tools.standalone
would create a parser file with these changes already in place), the addition of the Rule().cb_name
attribute caused lots of errors/failed tests – and I couldn’t be positive where in the package to replace rule.alias
and where not to. So I’m pretty sure it’s not the way to go. Thoughts?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Is there a good (standalone) PHPDoc parser class or function ...
I explicitly cannot use PEAR or any such library, it has to be relatively standalone. Any given solution that is better than using...
Read more >Parser FAQ - The Stanford Natural Language Processing Group
The main tool remaining is to run multiple parsers at once in parallel. If you have a machine with enough memory and multiple...
Read more >xml.parsers.expat — Fast XML parsing using Expat — Python ...
An entity reference referred to an entity which was declared with a notation, so cannot be parsed. An attribute was used more than...
Read more >Parse::Yapp(3)
Parse::Yapp - Perl extension for generating and using LALR parsers. ... Note that in Parse::Yapp, a lhs cannot appear more than once as...
Read more >Parsing in JavaScript: all the tools and libraries you can use
You may need to pick the second option if you have particular needs. Both in the sense that the language you need to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should work now on
master
.Thanks for the bug report. I know what’s the problem, and I plan to fix it soon.