Skip to content

Pattern for implementing syntactic sugar #1536

Answered by erezsh
nchammas asked this question in Q&A
Discussion options

You must be logged in to vote

I think the easiest solution would be to just use a shared helper. Something like this:

class VehicleQuery(Interpreter):
    @v_args(inline=True)
    def maintenance_expr(self, maintenance_type: str):
        return self._event_expr(...)

    @v_args(tree=True)
    def event_expr(self, node: Tree):
         self._event_expr(...)

    def _event_expr(self, make: str, type: str, ...):
         ...

It can also be an external function and not a method. But anyway, names that start with underscore are safe, Lark won't call them.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@nchammas
Comment options

@erezsh
Comment options

Answer selected by nchammas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants