Visitor Combination And Traversal Control

Program-Transformation.Org: The Program Transformation Wiki
Visitor Combination and Traversal Control

by JoostVisser

This paper describes VisitorCombinators. These are implementations of the Visitor interface that can be used to compose new visitors from given ones. The paper also describes the generic visitor combinator framework Tools.JJTraveler, and the visitor generator Tools.JJForester, which supports instantation of this framework for a given grammar.

See:

Abstract

The Visitor design pattern allows the encapsulation of poly- morphic behavior outside the class hierarchy on which it operates. A common application of Visitor is the encapsu- lation of tree traversals. Unfortunately, visitors resist com- position and allow little traversal control.

To remove these limitations, we introduce visitor combina- tors. These are implementations of the visitor interface that can be used to compose new visitors from given ones. The set of combinators we propose includes traversal combina- tors that can be used to obtain full traversal control.

A clean separation can be made between the generic parts of the combinator set and the parts that are speci c to a particular class hierarchy. The generic parts form a reusable framework. The specific parts can be generated from a (tree) grammar. Due to this separation, programming with visitor combinators becomes a form of generic programming with signi cant reuse of (visitor) code.