Closed skepppy closed 9 hours ago
Thanks for reporting it.
The documentation is currently incorrect: v_args
does not apply to visitors, only to transformers. Sorry!
Perhaps it would be possible to support it. I'll be open to such a PR.
Anyway, we should definitely fix the docs to make this clear.
Thanks for the swift response! :) Right now, I think the docs are partly ambiguous, because it talks about visitor functions and class definitions.
A convenience decorator factory for modifying the behavior of user-supplied visitor methods.
Gives the impression that any "visitor" class would support this behavior, so I would think any class in ./lark/visitors.py
that allows for visiting the AST.
By default, callback methods of transformers/visitors accept one argument - a list of the node’s children.
This formulates it another way, making a distinction between transformers/visitors, while there also being interpreters, I don't know if they are included as well.
v_args can modify this behavior. When used on a transformer/visitor class definition, it applies to all the callback methods inside it.
This is another way of writing the same in a different way, referring to the Transformer
and Visitor
class definitions specifically.
I tried to rephrase it in PR #1458 so that it is clear that v_args()
only works for Transformer
classes. If more changes are required, please let me know :)
Can we consider this issue as resolved?
Describe the bug
I want to write a
Visitor
class that usesinline=True
, but Lark seems to ignore it and I do not understand why.The documentation writes:
Furthermore, it writes:
With this, I would expect subclasses of the
Visitor
class to receive parsed tokens from the abstract syntax tree (AST) through its parameters. However, I am still receiving a single parameter with typelark.Tree
.Maybe it's something else that is wrong and causes , if so, please enlighten me.
To Reproduce
I tried to create a relatively simple script that shows the problem I'm encountering. It is a script that creates both a
Transformer
and aVisitor
class, both decorated withv_args(inline=True)
, but theTransformer
class actually receiving the words through its parameters, while theVisitor
class still receives thelark.Tree
class. According to the docs, it says that it should work for both classes, but theVisitor
class seems to ignore it.Furthermore, I'm running the following:
If I run the above script, I get an exception, but only for the
TransformNumbers
, not forVisitNumbers
: