-
|
Say I'm developing a language that lets you filter vehicle events on a timeline using an expression like this: As a convenient shorthand for users, I would like to enable them to write something like this: Which is just syntactic sugar for this: In my Lark class VehicleQuery(Interpreter):
@v_args(inline=True)
def maintenance_expr(self, maintenance_type: str):
...
return event_expr(...)
def event_expr(self, node: Tree):
...I am not sure how to construct the appropriate |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
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. |
Beta Was this translation helpful? Give feedback.
I think the easiest solution would be to just use a shared helper. Something like this:
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.