-
Notifications
You must be signed in to change notification settings - Fork 60
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
Better warnings for conflicts #28
Comments
+1 |
The same for parser errors. Simple |
I have something like this now, for reduce/reduce conflicts, does that look good? Warning output:
Here's the code change, I assume this would need tests: diff --git a/rply/parsergenerator.py b/rply/parsergenerator.py
index 243705f..9ca2a25 100644
--- a/rply/parsergenerator.py
+++ b/rply/parsergenerator.py
@@ -205,10 +205,15 @@ class ParserGenerator(object):
stacklevel=2,
)
if table.rr_conflicts:
+ conflicts = table.rr_conflicts
+ prod_str = lambda s: s.split('(', 1)[1][:-1]
+ printable = [(prod_str(i[1]), prod_str(i[2])) for i in conflicts]
+ details = '\n'.join(' %r vs %r' % i for i in printable)
warnings.warn(
- "%d reduce/reduce conflict%s" % (
+ "%d reduce/reduce conflict%s:\n%s" % (
len(table.rr_conflicts),
- "s" if len(table.rr_conflicts) > 1 else ""
+ "s" if len(conflicts) > 1 else "",
+ details,
),
ParserGeneratorWarning,
stacklevel=2, |
FWIW, PLY puts the conflict info in a |
+1 it'll be a great help when there are hundreds of production rules. Trying to get some output for shift/reduce conflicts now. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be nice if conflicts would report something a little more actionable than just the fact that a conflict exists. For example, reporting a relevant LRItem provides a clue, at least.
The text was updated successfully, but these errors were encountered: