Skip to content

Visitor<TContext, TNode, TResult> Class ​

Definition ​

A visitor for a syntax tree. A visitor is called for a node and returns a value for it. Unlike a Listener<TContext, TNode>, which walks the whole tree itself, a visitor controls the walk: it visits whichever children it needs, in whatever order it needs, and combines their results into its own. That makes visitors the natural fit for evaluating or transforming a tree into a value, especially when not every child should be visited, for example, short-circuit evaluation.

c#
public abstract class Visitor<TContext, TNode, TResult>
   where TNode : Node<TNode>

View source

Type Parameters ​

NameDescription
TContextThe type of the context object.
TNodeThe type of the nodes to visit.
TResultThe type of the result of visiting a node.

Constructors ​

NameDescription
Visitor()

Methods ​

NameDescription
Visit(TContext, TNode)Visits the specified node and returns the result.
VisitChildren(TContext, TNode)Visits all the children of the specified node in order and returns their results.
VisitNode(TContext, TNode)Called to visit a node.