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.

Inject terminals into grammer

See original GitHub issue

I’m looking for a way to inject certain terminals into a grammer when defining the parser. I need this for internationalization.

I’m looking for something similar like the %import, but I don’t want to import it from a file but from Python when defining the parser:

parser = Lark.open("grammer.lark", parser="lalr", terminals={"_FOO": "foo", "_BAR": "bar"})
parser.parse(...)

In the grammer.lark I could then make use of _FOO and _BAR. Is something like that already possible? Would it make sense to add such a feature to lark?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:23 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
erezshcommented, Sep 19, 2019

This is already available as version 0.7.6a1

1reaction
erezshcommented, Jul 10, 2019

I suppose you want it to support many languages, right? In that case, you’ll have to define quite a few terminals, and possibly even nontrivials ones, which might make this call pretty awkward.

I’m much more inclined to add an include keyword, for importing additional lark files on top of the current one. So you can do something like:

parser = Lark.open("grammer.lark", parser="lalr", include=["translations/spanish.lark"])
parser.parse(...)

What do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

NLTK: can I add terminal to grammar that is already generated
I have generated grammar from atis grammar, now I wanted to add some rules of my own especially terminals from sentence could I...
Read more >
nltk.grammar
A grammar consists of a start state and a set of productions. The set of terminals and nonterminals is implicitly specified by the...
Read more >
How to implement a regular grammar?
There are many types of grammar expressions. First, we will teach generate how to deal with each of the non-terminal symbols.
Read more >
Chapter 1: Unambiguous LR Grammar for Simple Calculator.
The grammar used in this Chapter will only use the first two forms: a and (a) . The right-hand side of a rule...
Read more >
ML-Yacc User's Manual Version 2.3
Each symbol in the grammar may have a value (i.e. attribute) associated with it. ... Corrections which insert a terminal on this list...
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