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 polymorphic behavior outside the class hierarchy on which it operates. A common application of Visitor is the encapsulation of tree traversals. Unfortunately, visitors resist composition and allow little traversal control.

To remove these limitations, we introduce visitor combinators. 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 combinators 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 significant reuse of (visitor) code.