|
|
|
|
|
by ufo
2000 days ago
|
|
I find that this kind of pattern can be useful if you have a default implementation for each visit_foo method. For example, suppose that you want to create a traversal that walks through the entire Ast and does something special on just the Name nodes. And another traversal that does something special on just the integer literal nodes. One way to do this is to create a default traversal that walks through the entire tree without doing anything and then create a "subclass" that overrides just the visit_name and another that overrides just the visit_expr method. One place that I've seen this in the wild is the Ocaml compiler: * https://github.com/ocaml/ocaml/blob/trunk/parsing/ast_iterat...
* https://github.com/ocaml/ocaml/blob/trunk/parsing/ast_mapper... |
|