Inject terminals into grammer
See original GitHub issueI’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:
- Created 4 years ago
- Comments:23 (22 by maintainers)
Top 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 >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
This is already available as version
0.7.6a1
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:What do you think?