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

Better warnings for conflicts #28

Open
djc opened this issue Jun 8, 2014 · 5 comments
Open

Better warnings for conflicts #28

djc opened this issue Jun 8, 2014 · 5 comments

Comments

@djc
Copy link
Contributor

djc commented Jun 8, 2014

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.

@prologic
Copy link

+1

@mcepl
Copy link

mcepl commented Jan 9, 2015

The same for parser errors. Simple ParsingError is kind of useless.

@djc
Copy link
Contributor Author

djc commented Oct 8, 2015

I have something like this now, for reduce/reduce conflicts, does that look good? Warning output:

rnc2rng/parser.py:328: ParserGeneratorWarning: 10 reduce/reduce conflicts:
  'particle-choice -> inner-particle' vs 'particle-group -> inner-particle'
  'particle-choice -> inner-particle' vs 'particle-group -> inner-particle'
  'particle-choice -> inner-particle' vs 'particle-group -> inner-particle'
  'particle-choice -> inner-particle' vs 'particle-group -> inner-particle'
  'particle-choice -> inner-particle' vs 'particle-group -> inner-particle'
  'particle-choice -> inner-particle' vs 'particle-interleave -> inner-particle'
  'particle-choice -> inner-particle' vs 'particle-interleave -> inner-particle'
  'particle-choice -> inner-particle' vs 'particle-interleave -> inner-particle'
  'particle-choice -> inner-particle' vs 'particle-interleave -> inner-particle'
  'particle-choice -> inner-particle' vs 'particle-interleave -> inner-particle'
  parser = pg.build()

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,

@refi64
Copy link

refi64 commented Oct 8, 2015

FWIW, PLY puts the conflict info in a parser.out file.

@nobodxbodon
Copy link
Contributor

+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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants