lark icon indicating copy to clipboard operation
lark copied to clipboard

Miscellaneous improvements to the behavior and documentation of Visitor, Transformer, Interpreter, and friends

Open nchammas opened this issue 5 months ago • 5 comments

This PR makes the following improvements.

Documentation:

  • Add docstrings for visit_children_decor and various methods of Interpreter.
  • Correct the top-level docs for Visitor to clarify that it can traverse the tree in either direction.
  • Move utilities into their own section and add documentation for visit_children_decor, which was previously not visible.

Behavior:

  • Have visit_children_decor raise a TypeError if applied to a method of any class other than Interpreter.
  • Have v_args raise a TypeError if applied to a Visitor or its methods. I had to get help from GPT to figure out to make this check work. I'm not confident in the logic.

nchammas avatar Jul 14 '25 01:07 nchammas

visit_topdown would actually get the Interpreter to walk the tree bottom up

Can you explain this comment? Interpreter.top_down() would just use the __default__() method, no?

erezsh avatar Jul 14 '25 08:07 erezsh

Ah, I think I misinterpreted the behavior and jumped to the wrong conclusion.

Is the behavior of Interpreter.visit_topdown() fine as it is on master? Or is my proposed patch correct and just needs a fixed description?

nchammas avatar Jul 14 '25 15:07 nchammas

@nchammas Well, I can see how it was confusing. But I don't think adding visit_topdown fixes anything. Interpreter is behaving as expected, and if it's not implemented with the best design, that's another matter, but adding this method won't change that.

erezsh avatar Jul 14 '25 16:07 erezsh

Maybe it would be better to remove the __getattr__, but that would be slightly backwards-incompatible, in case anyone relied on this behavior, for some reason.

erezsh avatar Jul 14 '25 17:07 erezsh

@erezsh - No rush; just wanted to check in again if I can do anything to move this PR forward.

nchammas avatar Aug 27 '25 09:08 nchammas