Struct hime_redist::parsers::subtree::SubTree
source · pub struct SubTree { /* private fields */ }
Expand description
Represents a sub-tree in an AST
A sub-tree is composed of a root with its children.
The children may also have children.
The maximum depth of a sub-tree is 2 (root, children and children’s children), in which case the root is always a replaceable node.
The internal representation of a sub-tree is based on arrays.
The organization is that a node’s children are immediately following it in the array.
For example, the tree A(B(CD)E(FG))
is represented as [ABCDEFG]
.
Implementations§
source§impl SubTree
impl SubTree
sourcepub fn get_label_at(&self, index: usize) -> TableElemRef
pub fn get_label_at(&self, index: usize) -> TableElemRef
Gets the label of the node at the given index
sourcepub fn set_label_at(&mut self, index: usize, label: TableElemRef)
pub fn set_label_at(&mut self, index: usize, label: TableElemRef)
Sets the label of the node at the given index
sourcepub fn get_action_at(&self, index: usize) -> TreeAction
pub fn get_action_at(&self, index: usize) -> TreeAction
Gets the tree action applied onto the node at the given index
sourcepub fn set_action_at(&mut self, index: usize, action: TreeAction)
pub fn set_action_at(&mut self, index: usize, action: TreeAction)
Sets the tree action applied onto the node at the given index
sourcepub fn get_children_count_at(&self, index: usize) -> usize
pub fn get_children_count_at(&self, index: usize) -> usize
Gets the number of children of the node at the given index
sourcepub fn set_children_count_at(&mut self, index: usize, count: usize)
pub fn set_children_count_at(&mut self, index: usize, count: usize)
Sets the number of children of the node at the given index
sourcepub fn setup_root(&mut self, symbol: TableElemRef, action: TreeAction)
pub fn setup_root(&mut self, symbol: TableElemRef, action: TreeAction)
Initializes the root of this sub-tree
sourcepub fn copy_to(&self, destination: &mut SubTree) -> usize
pub fn copy_to(&self, destination: &mut SubTree) -> usize
Copy the content of this sub-tree to the given sub-tree’s buffer beginning at the given index This methods only applies in the case of a depth 1 sub-tree (only a root and its children). The results of this method in the case of a depth 2 sub-tree is undetermined.
sourcepub fn copy_children_to(&self, destination: &mut SubTree) -> usize
pub fn copy_children_to(&self, destination: &mut SubTree) -> usize
Copy the root’s children of this sub-tree to the given sub-tree’s buffer beginning at the given index This methods only applies in the case of a depth 2 sub-tree.
sourcepub fn commit_children_of(&mut self, index: usize, ast: &mut Ast<'_>)
pub fn commit_children_of(&mut self, index: usize, ast: &mut Ast<'_>)
Commits the children of a sub-tree in this buffer to the final ast If the index is 0, the root’s children are committed, assuming this is a depth-1 sub-tree. If not, the children of the child at the given index are committed.
sourcepub fn push(&mut self, symbol: TableElemRef, action: TreeAction) -> usize
pub fn push(&mut self, symbol: TableElemRef, action: TreeAction) -> usize
Pushes a new node into this buffer
sourcepub fn move_range(&mut self, from: usize, to: usize, length: usize)
pub fn move_range(&mut self, from: usize, to: usize, length: usize)
Moves a range of items within the buffer