Extending Grammar Without Changing Grammar File
See original GitHub issueHi again,
You may recall that I’m using your Python 3 grammar (#57). I reached the point where I can transpile simple Python code into Haxe code (yay!)
The next problem I’m faced with is that Haxe contains certain constructs that don’t exist in Python (or in the grammar); for example, you need to specify the override
keyword to override a method; and you can use the @
notation for attributes (Python does have something similar, but less expressive).
I’m still hoping you’ll decide to officially support and maintain the Python 3 grammar! In the meanwhile, what’s the best way of adding these extensions to the parser, without changing the built-in grammar? Right now, I’m abusing long strings as comments to store my own syntax, but this seems wrong. (I tried doing the same thing with regular comments, but couldn’t figure out how to modify the grammar to stop ignoring them and then get a generator to visit them.)
Is the right approach a two-step process (run it through two grammars, first mine then the Python one)? But if I do that, the Python stage will break because those tokens aren’t valid Python code (eg. override def function_name ...
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
I think the easiest solution would be to have two Lark instances, once for each grammar. However, you can also use one instance, and choose between them by giving
start
toLark.parse()
Hello!
I have a situation where we have two grammars, a normal one, and an extended version.
How could we achieve something like this for the extended:
And the program will choose to use this grammar or the base depending on the situation?