mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-05 23:28:45 +00:00
mdesk: at tree introspection
This commit is contained in:
+62
-11
@@ -285,31 +285,82 @@ token_match(Token a, Token b) {
|
||||
|
||||
//- rjf: flag conversions
|
||||
|
||||
internal NodeFlags node_flags_from_token_flags(TokenFlags flags);
|
||||
inline NodeFlags
|
||||
node_flags_from_token_flags(TokenFlags flags)
|
||||
{
|
||||
NodeFlags result = 0;
|
||||
result |= NodeFlag_Identifier *!!(flags & TokenFlag_Identifier );
|
||||
result |= NodeFlag_Numeric *!!(flags & TokenFlag_Numeric );
|
||||
result |= NodeFlag_StringLiteral *!!(flags & TokenFlag_StringLiteral );
|
||||
result |= NodeFlag_Symbol *!!(flags & TokenFlag_Symbol );
|
||||
result |= NodeFlag_StringSingleQuote *!!(flags & TokenFlag_StringSingleQuote);
|
||||
result |= NodeFlag_StringDoubleQuote *!!(flags & TokenFlag_StringDoubleQuote);
|
||||
result |= NodeFlag_StringTick *!!(flags & TokenFlag_StringTick );
|
||||
result |= NodeFlag_StringTriplet *!!(flags & TokenFlag_StringTriplet );
|
||||
return result;
|
||||
}
|
||||
|
||||
//- rjf: nil
|
||||
|
||||
internal B32 node_is_nil(Node *node);
|
||||
B32 node_is_nil(Node* node) { return (node == 0 || node == nil_node() || node->kind == NodeKind_Nil); }
|
||||
|
||||
//- rjf: iteration
|
||||
|
||||
#define MD_EachNode(it, first) (Node *it = first; !node_is_nil(it); it = it->next)
|
||||
#define each_node(it, first) (Node *it = first; !node_is_nil(it); it = it->next)
|
||||
|
||||
internal NodeRec node_rec_depth_first(Node *node, Node *subtree_root, U64 child_off, U64 sib_off);
|
||||
MD_API NodeRec node_rec_depth_first(Node *node, Node *subtree_root, U64 child_off, U64 sib_off);
|
||||
|
||||
#define node_rec_depth_first_pre(node, subtree_root) node_rec_depth_first((node), (subtree_root), offset_of(Node, first), offset_of(Node, next))
|
||||
#define node_rec_depth_first_pre_rev(node, subtree_root) node_rec_depth_first((node), (subtree_root), offset_of(Node, last), offset_of(Node, prev))
|
||||
|
||||
//- rjf: tree building
|
||||
|
||||
internal Node* push_node (Arena *arena, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset);
|
||||
internal void node_insert_tag (Node *parent, Node *prev_child, Node *node);
|
||||
internal void node_insert_child(Node *parent, Node *prev_child, Node *node);
|
||||
internal void node_push_child (Node *parent, Node *node);
|
||||
internal void node_push_tag (Node *parent, Node *node);
|
||||
internal void unhook (Node *node);
|
||||
Node* push_node (Arena *arena, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset);
|
||||
void node_insert_tag (Node *parent, Node *prev_child, Node *node);
|
||||
void node_insert_child(Node *parent, Node *prev_child, Node *node);
|
||||
void node_push_child (Node *parent, Node *node);
|
||||
void node_push_tag (Node *parent, Node *node);
|
||||
void unhook (Node *node);
|
||||
|
||||
//- rjf: tree introspection
|
||||
inline Node*
|
||||
push_node(Arena* arena, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset) {
|
||||
Node* node = push_array(arena, Node, 1);
|
||||
node->first = node->last = node->parent = node->next = node->prev = node->first_tag = node->last_tag = nil_node();
|
||||
node->kind = kind;
|
||||
node->flags = flags;
|
||||
node->string = string;
|
||||
node->raw_string = raw_string;
|
||||
node->src_offset = src_offset;
|
||||
return node;
|
||||
}
|
||||
|
||||
inline void
|
||||
node_insert_child(Node* parent, Node* prev_child, Node* node) {
|
||||
node->parent = parent;
|
||||
dll_insert_npz(nil_node(), parent->first, parent->last, prev_child, node, next, prev);
|
||||
}
|
||||
|
||||
inline void
|
||||
node_insert_tag(Node* parent, Node* prev_child, Node* node) {
|
||||
node->kind = NodeKind_Tag;
|
||||
node->parent = parent;
|
||||
dll_insert_npz(nil_node(), parent->first_tag, parent->last_tag, prev_child, node, next, prev);
|
||||
}
|
||||
|
||||
inline void
|
||||
node_push_child(Node* parent, Node* node) {
|
||||
node->parent = parent;
|
||||
dll_push_back_npz(nil_node(), parent->first, parent->last, node, next, prev);
|
||||
}
|
||||
|
||||
inline void
|
||||
node_push_tag(Node* parent, Node* node) {
|
||||
node->kind = NodeKind_Tag;
|
||||
node->parent = parent;
|
||||
dll_push_back_npz(nil_node(), parent->first_tag, parent->last_tag, node, next, prev);
|
||||
}
|
||||
|
||||
//- rjf: tree introspectionhttps://github.com/Ed94/metadesk
|
||||
|
||||
internal Node* node_from_chain_string(Node *first, Node *opl, String8 string, StringMatchFlags flags);
|
||||
internal Node* node_from_chain_index (Node *first, Node *opl, U64 index);
|
||||
|
||||
Reference in New Issue
Block a user