Sourceror.Zipper (Sourceror v0.11.0) View Source
Implements a Zipper for the Elixir AST based on Gérard Huet Functional
pearl: the
zipper
paper and Clojure's clojure.zip
API.
A zipper is a data structure that represents a location in a tree from the
perspective of the current node, also called focus. It is represented by a
2-tuple where the first element is the focus and the second element is the
metadata/context. When the focus is the topmost node, the metadata is nil
,
or :end
after the end of a traversal.
Link to this section Summary
Functions
Inserts the item as the rightmost child of the node at this zipper, without moving.
Returns true if the node is a branch.
Returns a list of children of the node.
Returns the zipper of the leftmost child of the node at this zipper, or nil if no there's no children.
Returns true if the zipper represents the end of a depth-first walk.
Returns a zipper to the node that satisfies the predicate function, or nil
if none is found.
Inserts the item as the leftmost child of the node at this zipper, without moving.
Inserts the item as the left sibling of the node at this zipper, without
moving. Raises an ArgumentError
when attempting to insert a sibling at the
top level.
Inserts the item as the right sibling of the node at this zipper, without
moving. Raises an ArgumentError
when attempting to insert a sibling at the
top level.
Returns the zipper of the left sibling of the node at this zipper, or nil.
Returns the leftmost sibling of the node at this zipper, or itself.
Returns a new branch node, given an existing node and new children.
Returns the following zipper in depth-first pre-order. When reaching the end,
returns a distinguished zipper detectable via end?/1
. If it's already at
the end, it stays there.
Returns the node at the zipper.
Returns the previous zipper in depth-first pre-order. If it's already at the end, it returns nil.
Removes the node at the zipper, returning the zipper that would have preceded it in a depth-first walk.
Replaces the current node in the zipper with a new node.
Returns the zipper of the right sibling of the node at this zipper, or nil.
Returns the rightmost sibling of the node at this zipper, or itself.
Walks the zipper all the way up and returns the root node.
Returns the zipper of the right sibling of the node at this zipper, or the next zipper when no right sibling is available.
Walks the zipper all the way up and returns the top zipper.
Traverses the tree in depth-first pre-order calling the given function for each node.
Traverses the tree in depth-first pre-order calling the given function for each node with an accumulator.
Traverses the tree in depth-first pre-order calling the given function for each node.
Traverses the tree in depth-first pre-order calling the given function for each node with an accumulator.
Returns the zipper of the parent of the node at this zipper, or nil if at the top.
Replaces the current node in the zipper with the result of applying fun
to
the node.
Creates a zipper from a tree node.
Link to this section Types
Link to this section Functions
Inserts the item as the rightmost child of the node at this zipper, without moving.
Specs
Returns true if the node is a branch.
Specs
Returns a list of children of the node.
Specs
Returns the zipper of the leftmost child of the node at this zipper, or nil if no there's no children.
Specs
Returns true if the zipper represents the end of a depth-first walk.
Specs
Returns a zipper to the node that satisfies the predicate function, or nil
if none is found.
The optional second parameters specifies the direction
, defaults to
:next
.
Inserts the item as the leftmost child of the node at this zipper, without moving.
Specs
Inserts the item as the left sibling of the node at this zipper, without
moving. Raises an ArgumentError
when attempting to insert a sibling at the
top level.
Specs
Inserts the item as the right sibling of the node at this zipper, without
moving. Raises an ArgumentError
when attempting to insert a sibling at the
top level.
Specs
Returns the zipper of the left sibling of the node at this zipper, or nil.
Specs
Returns the leftmost sibling of the node at this zipper, or itself.
Specs
Returns a new branch node, given an existing node and new children.
Returns the following zipper in depth-first pre-order. When reaching the end,
returns a distinguished zipper detectable via end?/1
. If it's already at
the end, it stays there.
Specs
Returns the node at the zipper.
Specs
Returns the previous zipper in depth-first pre-order. If it's already at the end, it returns nil.
Specs
Removes the node at the zipper, returning the zipper that would have preceded it in a depth-first walk.
Specs
Replaces the current node in the zipper with a new node.
Specs
Returns the zipper of the right sibling of the node at this zipper, or nil.
Specs
Returns the rightmost sibling of the node at this zipper, or itself.
Specs
Walks the zipper all the way up and returns the root node.
Specs
Returns the zipper of the right sibling of the node at this zipper, or the next zipper when no right sibling is available.
This allows to skip subtrees while traversing the siblings of a node.
If no right sibling is available, this function returns the same value as
next/1
.
The optional second parameters specifies the direction
, defaults to
:next
.
The function skip/1
behaves like the :skip
in traverse_while/2
and
traverse_while/3
.
Specs
Walks the zipper all the way up and returns the top zipper.
Specs
Traverses the tree in depth-first pre-order calling the given function for each node.
If the zipper is not at the top, just the subtree will be traversed.
The function must return a zipper.
Specs
Traverses the tree in depth-first pre-order calling the given function for each node with an accumulator.
If the zipper is not at the top, just the subtree will be traversed.
Specs
traverse_while( zipper(), (zipper() -> {:cont, zipper()} | {:halt, zipper()} | {:skip, zipper()}) ) :: zipper()
Traverses the tree in depth-first pre-order calling the given function for each node.
The traversing will continue if the function returns {:cont, zipper}
,
skipped for {:skip, zipper}
and halted for {:halt, zipper}
If the zipper is not at the top, just the subtree will be traversed.
The function must return a zipper.
Specs
traverse_while( zipper(), term(), (zipper(), term() -> {:cont, zipper(), term()} | {:halt, zipper(), term()} | {:skip, zipper(), term()}) ) :: {zipper(), term()}
Traverses the tree in depth-first pre-order calling the given function for each node with an accumulator.
The traversing will continue if the function returns {:cont, zipper, acc}
,
skipped for {:skip, zipper, acc}
and halted for {:halt, zipper, acc}
If the zipper is not at the top, just the subtree will be traversed.
Specs
Returns the zipper of the parent of the node at this zipper, or nil if at the top.
Specs
Replaces the current node in the zipper with the result of applying fun
to
the node.
Specs
Creates a zipper from a tree node.