chickadee » sxml-transforms » replace-range

replace-range beg-pred end-pred forestprocedure
   procedure: replace-range:: BEG-PRED x END-PRED x FOREST -> FOREST

Traverse a forest depth-first and cut/replace ranges of nodes.

The nodes that define a range don't have to have the same immediate parent, don't have to be on the same level, and the end node of a range doesn't even have to exist. A replace-range procedure removes nodes from the beginning node of the range up to (but not including) the end node of the range. In addition, the beginning node of the range can be replaced by a node or a list of nodes. The range of nodes is cut while depth-first traversing the forest. If all branches of the node are cut a node is cut as well. The procedure can cut several non-overlapping ranges from a forest.

   replace-range:: BEG-PRED x END-PRED x FOREST -> FOREST

where

   type FOREST = (NODE ...)
   type NODE = Atom | (Name . FOREST) | FOREST

The range of nodes is specified by two predicates, beg-pred and end-pred.

   beg-pred:: NODE -> #f | FOREST
   end-pred:: NODE -> #f | FOREST

The beg-pred predicate decides on the beginning of the range. The node for which the predicate yields non-#f marks the beginning of the range The non-#f value of the predicate replaces the node. The value can be a list of nodes. The replace-range procedure then traverses the tree and skips all the nodes, until the end-pred yields non-#f. The value of the end-pred replaces the end-range node. The new end node and its brothers will be re-scanned. The predicates are evaluated pre-order. We do not descend into a node that is marked as the beginning of the range.