fling icon indicating copy to clipboard operation
fling copied to clipboard

Improve the structure of generated AST visitors

Open homedirectory opened this issue 2 years ago • 0 comments

AST visitor generation was producing visitors that were hardly useful:

  1. visit methods were final which prevented implementations from controlling the descending behaviour
  2. whileVisiting methods were hardly useful due to point 1

Consider the task of wrapping a parent AST node in parentheses, including its children. This could not be achieved using previous AST visitors.

This change makes visitors be generated in the fashion of javax.lang.model.util.ElementScanner. It allows implementations to control the descent like so:

void visit(ParentNode node) {
    print("("); // before visiting children
    Visitor.super.visit(node); // descend
    print(")"); // after having visited children
}

homedirectory avatar Feb 08 '24 14:02 homedirectory