antlr/antlr4 — Issue #9: Make generic visitor with parameterized return values: XVisitor<T> upon -visitor option
Author: parrt
Created: 2012-02-11 19:21:58+00:00
State: open

add the following double dispatch:

public void accept(XVisitor visitor) { visitor.visit(this); }

and generate XVisitor. Make a BaseXVisitor that has a

void visitChildren(ParserRuleContext ctx) {
for each child c: visit(c);
}

And generates the following default implementations:

void visit(slistContext ctx) { visitChildren(p); }

I guess we also need a generic method in ParserRuleContext:

public abstract void accept(XVisitor visitor);

People can do things like this:

int visit(NodeType n) { return n.left.accept(this) + n.right.accept(this); }