Docs enhancement on visitor with defaults #1919
-
Hi, thank you for such a cool lib. While implementing a visitor with defaults I have not fully understood the implicit logic that it does. If the overload of visitor rule is present / the method for rule is defined, does the chevrotain still automatically calls the node's children visitor methods? Or if the method is present it becomes the method's obligation to call the visit methods for children (seems like this is the case)? Maybe this could be added in the docs to reduce the ambiguity. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello @ierehon1905 From the code it appears that you need to explicitly invoke the visitor for the children when you provide an implementation. I guess the reasoning behind this is that if you implemented an "handler" for a specific grammar rule You can always add additional helpers and logic for your Other ideas:
Considering the cst data structure is fairly simple and consistent, you may also choose to implement If you do so, perhaps you will have ideas how to improve the bulit-in one in Chevrotain, see: #1039 |
Beta Was this translation helpful? Give feedback.
Hello @ierehon1905
From the code it appears that you need to explicitly invoke the visitor for the children when you provide an implementation.
I guess the reasoning behind this is that if you implemented an "handler" for a specific grammar rule
You likely want to collect / assemble the individual children visitor results in some manner, not merely invoke the visitor on those.
You can always add additional helpers and logic for your
visitor
, e.g:Other ideas: