Initial Commit
This commit is contained in:
789 files changed
+149185
No files matched your search
@@ -0,0 +1,64 @@
|
||||
#! @file node_walk.sakura
|
||||
#! @author John Christman (sorakatadzuma@gmail.com)
|
||||
#! @copyright Malunal Studios, LLC.
|
||||
#! @license MIT
|
||||
#!
|
||||
#! Contains the walk of a node of the syntax tree and the nodes under it, which
|
||||
#! the scans lowering makes of what a body names share, and the checker's writing
|
||||
#! of an expression as it is written.
|
||||
|
||||
module sakura::analyzer;
|
||||
|
||||
|
||||
#! A walk of a node of the syntax tree and the nodes under it, each before the
|
||||
#! nodes it holds. The walk goes under a node only where it is asked to, so a
|
||||
#! scan may pass over what a node holds, or go under only some of it.
|
||||
pub struct node_walk {
|
||||
var todo: vector<u32>; #! The nodes yet to be given, the next last, 0 standing for one absent.
|
||||
}
|
||||
|
||||
#! Walks a node and the nodes under it.
|
||||
#! @param node The node, or 0 for none.
|
||||
#! @returns The walk.
|
||||
pub def node_walk::new(node: u32): node_walk {
|
||||
var made := node_walk { todo = vector::<u32>::new() };
|
||||
made.todo.append(node);
|
||||
return made;
|
||||
}
|
||||
|
||||
#! Whether the walk has another node to give, passing over those absent.
|
||||
#! @param this The walk.
|
||||
#! @returns Whether it has.
|
||||
pub def node_walk::more(&mut this): bool {
|
||||
# It answers from within the loop, which keeps it small enough to be inlined.
|
||||
while this.todo.length != 0 {
|
||||
return true if this.todo.last != 0;
|
||||
this.todo.truncate();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#! Gives the next node, once `more` says there is one.
|
||||
#! @param this The walk.
|
||||
#! @returns The node.
|
||||
pub def node_walk::next(&mut this): u32 {
|
||||
val at: u32 = this.todo.last;
|
||||
this.todo.truncate();
|
||||
return at;
|
||||
}
|
||||
|
||||
#! Goes under a node: the nodes it holds are given next, the last its shape
|
||||
#! lists first.
|
||||
#! @param this The walk.
|
||||
#! @param tree The syntax tree.
|
||||
#! @param node The node.
|
||||
pub def node_walk::enter(&mut this, tree: &syntax, node: u32): void {
|
||||
tree.children(node, &mut this.todo);
|
||||
}
|
||||
|
||||
#! Goes under a node to one node it holds only, which is given next.
|
||||
#! @param this The walk.
|
||||
#! @param node The node held, or 0 for none.
|
||||
pub def node_walk::add(&mut this, node: u32): void {
|
||||
this.todo.append(node);
|
||||
}
|
||||
Reference in new issue
Block a user