question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Standalone parser cannot be used more than once

See original GitHub issue

That 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 in ParseTreeBuilder.create_callback(), causing errors elsewhere on subsequent runs.
  • In Python 3, the wrapper_chain = filter(...) in ParseTreeBuilder._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__(): add self.cb_name = None
  • Line 2 of Lark_StandAlone.__init__(): change to callbacks = {rule: getattr(callback, rule.cb_name or rule.origin, None) for rule in RULES.values()}
  • Line 19 of ParseTreeBuilder.create_callback(): change to rule.cb_name = internal_callback_name
  • Line 6 of ParseTreeBuilder._init_builders(): change to wrapper_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:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
erezshcommented, Apr 9, 2019

Should work now on master.

1reaction
erezshcommented, Dec 27, 2018

Thanks for the bug report. I know what’s the problem, and I plan to fix it soon.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found