-
-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import lark grammar written in one python project into another #1397
Comments
lark has facilities for this, namely If "project A" means an importable package, you can use the from lark.load_grammar import FromPackageLoader
Lark(... , import_paths=[FromPackageLoader('A', [''])
If |
Thanks, this works. Is there a way to also import all symbols from the grammar?
with
|
I would also love to know if there is a way to import everything from another grammar |
So I have tried it out. I must admit, I am a complete beginner with Lark and so I'm not sure if my error is due to that, or due to something else. What I a trying to do is create a grammar and parser for Snakemake which is a DSL built on top of python. i.e., any python syntax is valid snakemake syntax, and then there is snakemake-specific syntax on top of that. I want to keep the Snakemake grammar definition separate from the Python grammar, hence why I stumbled across this issue. Here is a small example of what I was trying to do (using lark installed from the linked branch ( from lark import Lark
lark = Lark(
r"""
%import python.*
start: file_input
ruledef: "rule" NAME ":" inputs outputs
inputs: "input:" files
outputs: "output:" files
files: (FILE_NAME)+
FILE_NAME: /[a-zA-Z0-9_\.\/]+/
"""
)
snakefile = """x = 42
rule foo:
input: 'foo.txt'
"""
def parse_snakemake_file():
return lark.parse(snakefile) When I try to import the
again, this could be my misunderstanding - I wasn't certain what to use for Also, I am happy to move this to a separate issue so as not to clutter this issue. |
@mbhall88 Feel free to open a new discussion/issue. Anyway, when importing grammars, you still have call all the relevant
|
What is your question?
How do I import lark grammar written in one python project into another.
E.g.
project A has
A/grammar.lark
fileproject B can import A
But
fails with
FileNotFoundError: [Errno 2] No such file or directory: 'A/grammar.lark'
Explain what you're trying to do, and what is obstructing your progress.
I am not sure if there is a nice way to do this. We are able to
%import common.<TERMINAL>
so I would like to think there should be a way to do this.The text was updated successfully, but these errors were encountered: