-
Notifications
You must be signed in to change notification settings - Fork 32
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
How far out is Table Caching? #52
Comments
It is on my TODO list but that list is huge. I can't tell when I'll start working on that. Any help is greatly appreciated. :) The idea is to dump the grammar and LR table in some portable format (JSON, Protocol buffers etc.). That would make it possible to share parsers between different parglare implementations (I have plan to work on ports to some other languages). I haven't played around with pickling yet but I guess with some pickling customization it should be doable. You don't have to pickle the whole parser object, just the tables, as the time you wait for the parser to be constructed is spent in table calculation. If you do make some progress using pickling please let us know. |
I might take a look at it... Could you point me to where in the code the tables are completed? |
Sure. This function creates LR table which is an instance of LRTable class. It is called here during |
Ok, I'm not going to pretend I understood all of the internals I was looking at, but it seems like the
But the caching problem would be a very neat and easy problem if it were possible to implement a flow more like this:
So my question for you, which I was not easily able to answer from reading the code, is this: Are you assigning actions to each (On a side note, I also looked at implementing my language in a couple of other tools, but I really like the flexibility that parglare offers, due to it being scannerless :) |
There is an unfortunate overlap of the concept From the point of view of table creation algorithm grammar actions are completely irrelevant. I wrote this table creation code a while ago so I would need some time to recover my understanding. :) As you can see in the code, What should be taken care of is to reconstruct the whole parser as it was before you must also reconstruct recognizers and user actions as they are inseparable part of the parsing process. Since those are python functions maybe you were having problem with that during pickling/unpickling. |
Alright, I'll try to take a deeper look at this, but its not likely to happen for at least a month. I need parglare to upgrade one of the build tools for my company's codebase, but not as badly as some other things are needed... |
@rexroni Sure, take your time. I expect to work on the table generation during next weeks as a part of better error reporting. I'll keep an eye on table caching issue along the way. |
Related to #36 |
First version of table caching is on the master branch. Please see the updates in the HISTORY.md and the docs. Let me know it you have any trouble. |
That's so awesome! Thank you for implementing that feature! I can now run it two times in a row, and Oddly though, I am noticing different parsing result the first time I run my code (without grammar.pgt) and the second time I run my code (with grammar.pgt). I am open to the possibility that I am a total noob at writing grammars, and it could be my fault... but it seems like they should produce the same results regardless, right? I will attach a sample program demonstrating the issue: This is the python file
This is
If I run
If I then run
The first time through it is correctly evaluating as the first line of the EXPR block, designed to catch builtin functions in my language like "dynamic":
But the second time it is evaluating as the sixth line, designed to catch user-defined functions:
(Note that F_PAREN means "function paren" and indicates a "(" which is not proceeded by a space, which allows for lists of expressions that can be space separated instead of comma separated). Is my grammar written in a way that it only happens to work without table caching, or is this a bug? |
Thanks for taking time to write a detailed report. There should be no difference in parsing between loaded and calculated table. There also should be no grammar that can't work with table caching so this must be a bug. I'll investigate. What is your Python version? |
The bug should be fixed now. Here is a regression test based on the code you provided. |
Awesome, it seems to be working great now! Glad I could help. |
In the documentation there is mention that it will be possible to not generate the parser on every startup... how far out is that feature?
Even though I had read that in the documentation before I started, I had naively assumed it would still be somehow possible to pickle the state of the parser and reload it on a future run. In fact, it is possible to serialize the parser using the
dill
module but it doesn't work quite right after I reload it.The text was updated successfully, but these errors were encountered: