Skip to content
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

Pickling/saving a generated grammar #34

Open
syegulalp opened this issue Apr 21, 2019 · 3 comments
Open

Pickling/saving a generated grammar #34

syegulalp opened this issue Apr 21, 2019 · 3 comments

Comments

@syegulalp
Copy link

Is there any way to take a given lexer/parser and pickle the results once the class is instantiated, and then reuse it later (to save us some startup time)? I tried to pickle a created Parser class with rules but the resulting file didn't seem to have any of the grammar data in it.

@dabeaz
Copy link
Owner

dabeaz commented Apr 25, 2019

The grammar rules/tables aren't stored in instances of Parser, but on the class itself. Thus, that information won't be stored as part of any kind of pickle.

Trying to cache parsing tables has caused no end of headaches in the related "PLY" project. SLY does not do that. How much startup time are you seeing?

@syegulalp
Copy link
Author

Not a gigantic amount, but it's a noticeable pause (maybe 0.3/0.4 sec?). It's more of a nice-to-have than a must-have, especially since the project (which I thank you for, BTW) is still so young.

Another idea that comes to mind is code generation a la ANTLR, but I imagine you are getting flashbacks and horror chills just contemplating the idea.

@syegulalp
Copy link
Author

BTW, here is how I'm currently implementing the lex/parse classes in my project:

https://github.com/syegulalp/Akilang/blob/master/aki/core/lex.py
https://github.com/syegulalp/Akilang/blob/master/aki/core/parse.py

(They're probably quite messy, I'm still learning)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants