-
-
Notifications
You must be signed in to change notification settings - Fork 414
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
Discard not supported while parsing with LALR #1084
Comments
Unfortunately isn't not that simple. If we were to add code to remove In the case of filtered = [x for x in filtered if x is not Discard] # <-- Need to add this
return self.node_builder(filtered) But that requires an additional iteration over every And of course, there's a simple "solution", which is to run |
P.S. it can also work if we change lalr_parser:151 to value = callbacks[rule]([x for x in s if x is not Discard]) But that's basically equivalent. |
There is a slightly more efficient solution, which is to keep track of all Discarded symbols in each state (in lockstep), and then subtract that from if value is Discard:
discarded_count[state] += 1
else:
value_stack.append(value) And later:
It should work, and probably won't add a lot of runtime cost. Just a lot of complication for something so small. So is it worth it? |
On principle, it seems like it should either work or it should be a documented caveat that passing a transformer to the parser doesn't honor Discard. You might want to mention that in the docs for both the parse() transformer argument and Discard, but definitely the latter. As a practical concern, I suppose I could go either way. I wasn't aware that tokens starting with That said, we were operating on an assumption that discarding parts of the tree simply was not possible. As soon as we tried to do a discard, we found it didn't work. So we haven't really had a chance to audit the Transformer to see how much we could simplify based on the idea that |
That's a valid point. I'll add it to the docs.
Let me know if that changes! |
Describe the bug
Discard
on a transformer (when passed to the parser) does not work with the LALR parser.To Reproduce
Here "does not work" means that the
Discard
singleton literally shows up in the output tree.This is because
parsers/lalr_parser.py
has no code to supportDiscard
.I think the fix will be something like the following. I don't think this is quite right, and I don't know enough about the code to go much further:
The text was updated successfully, but these errors were encountered: