3.3 astwalk.pl -- Flexible traversals of abstract syntax trees

author
Adrian Prantl <adrian@complang.tuwien.ac.at>
version
0.8.6-rc4
copyright
Copyright (C) 2008-2009 Adrian Prantl
license
See COPYING in the root folder of the SATIrE project

This module defines commonly-used transformation utilities for the AST exported by SATIrE. It represents an more flexible alternative to the transformation interface provided by module ast_transform.

[det]zip(+Tree, -Zipper)
Creates a new Zipper from Tree.

How to move around a tree and replace subtrees=branches?

At each node, we cut out a branch and replace it with a free variable <Gap>. The original branch is given as a separate argument, allowing us to bind the new branch to <Gap>.

In a way, this works just like Huet's zipper!

[det]unzip(?Zipper, ?Tree, ?Context)
Converts between the Zipper data structure and its contents.
[semidet]walk_to(+Zipper, +Context, -Zipper1)
[semidet]down(+Zipper, +BranchNum, -Zipper1)
Navigate downwards in the tree to child #BranchNum.

[semidet]up(+Zipper, -Zipper1)
Navigate upwards in the tree.
[semidet]right(+Zipper, -Zipper1)
Navigate to the next sibling in a tree or a list.
[semidet]top(+Zipper, -Zipper1)
Navigate back to the root of our tree.
To be done
Could be implemented more efficiently, too
[nondet]goto_function(+Zipper, ?Template, +Zipper1)
find a function like Template in a project or file and return its body if there is only a declaration available, the declaration will be returned
[det]distance_from_root(+Zipper, -Distance)
Return the current distance from the root node
next_preorder(+Zipper, -Zipper)
To be done
change name to next_tdlr Return the ``next'' node in a left-to-right traversal fashion. Algorithm: (rechtssucher) try down(1) else while not try right() do up()