Transformer: unpacking children
See original GitHub issueHello,
First, thanks for making Lark, I just discovered it, and I already like it a lot !
My suggestion would be this:
Adding a transform_unpack alternative to Transformer.transform which passes children in unpacked form:
For instance, in my transformer, a rule of the form
def int(s,x):
a,b, name, init = x
... do something with it
would become
def int(s, a,b, name, init):
which matches more closely the intuitive view of each node as a constructor in a pattern-matching.
Of course in variadic cases, you could still write
def int(s, a,b, name, init, *other_args):
I have only taken a cursory look, but this seems trivial to implement by adding an option to _call_userfunc and calling f(children) or f(*children) depending on whether it is passed. (_call_userfunc could also be duplicated if performance from the added “if” is a concern)
Would this be something you’re interested in implementing or, if I submit a PR to that effect, that you would be willing to integrate?
Cheers
Issue Analytics
- State:
- Created 9 months ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Sphinx is already set up, and iirc most of the docs are in markdown, so you don’t need to worry about it too much.
Once I have a bit more experience as a user — and have read the existing documentation — I definitely will.
It will force me to get into Sphinx as well, which I’ve avoided for a while…