dabeaz / sly

Sly Lex Yacc
Other
816 stars 107 forks source link

Add alternate function name for rule definitions in parsers #61

Closed fubuloubu closed 2 years ago

fubuloubu commented 3 years ago

Because the @_(str) rule decorator is "special" for this library, my static analysis plugins raise the alarm bells on every invocation because it can't find the name _, which makes it difficult to see when there actually is a problem.

It would be nice to have an "alias" (exported from sly) called something like @rule(str) that does the same thing it does now, but makes static analysis tools not raise a bunch of errors.

hadware commented 3 years ago

Alas, i think this isn't something @dabeaz doesn't agree with. This was discussed in #4 .

fubuloubu commented 3 years ago

I expected this, but it would be nice to at least have the option.


You can always alias rule = _ in a class if you want to use something more verbose

Note, this seems to work without issue:

# NOTE: Dummy function, to get `@_` to stop complaining in Parser
def _(fn, *args):
    raise

class Parser(SlyParser):
    ...
    @_("TOKEN")
    def rule(p):
         ...
hadware commented 3 years ago

this is a pretty good solution indeed!