sly icon indicating copy to clipboard operation
sly copied to clipboard

Pickling/saving a generated grammar

Open syegulalp opened this issue 6 years ago • 3 comments

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.

syegulalp avatar Apr 21 '19 20:04 syegulalp

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?

dabeaz avatar Apr 25 '19 12:04 dabeaz

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 avatar Apr 26 '19 15:04 syegulalp

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)

syegulalp avatar Apr 26 '19 15:04 syegulalp