alex / rply

An attempt to port David Beazley's PLY to RPython, and give it a cooler API.
BSD 3-Clause "New" or "Revised" License
381 stars 60 forks source link

meaning of "Production 'xxx' is not reachable"? #108

Open nobodxbodon opened 3 years ago

nobodxbodon commented 3 years ago

Take the test case for example:

https://github.com/alex/rply/blob/19a9e08c486b2723a2e2378df6edb6a26e2df4a5/tests/test_warnings.py#L83

Below are three cases with changed unused production rule:

case 1 -- No Warning

        @pg.production("main : VALUE")
        def main(p):
            return p[0]

        @pg.production("unused : main") 
        def unused(p):
            pass

case 2 -- Show Warning

        @pg.production("main : VALUE")
        def main(p):
            return p[0]

        @pg.production("unused : OTHER main")
        def unused(p):
            pass

case 3 -- No Warning

        @pg.production("main : VALUE")
        def main(p):
            return p[0]

        @pg.production("unused : VALUE main")
        def unused(p):
            pass

Now I'm quite puzzled about the meaning of this warning.

nobodxbodon commented 3 years ago

With some debugging, I realize that case 1 and 3 failed not because there was no warning, but because there were 2 warnings instead of 1. The additional warning was Token 'OTHER' is unused.

So I adjust the case by removing 'OTHER', and it still gives warning "Production 'unused' is not reachable":

        pg = ParserGenerator(["VALUE"])

        @pg.production("main : VALUE")
        def main(p):
            return p[0]

        @pg.production("unused : main")
        def unused(p):
            pass

Then, switch the order of the two production rules:

        pg = ParserGenerator(["VALUE"])

        @pg.production("unused : main")
        def unused(p):
            pass

        @pg.production("main : VALUE")
        def main(p):
            return p[0]

Now it gives no warning.

Seems a bug to me, as the order of production rules shouldn't have effects on the parsing outcome.