Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a737c05d5 | ||
|
|
44254614c1 | ||
|
|
6230ade289 | ||
|
|
a436f23601 | ||
|
|
3e325e4abd | ||
|
|
c427adbd22 | ||
|
|
1bb9425546 | ||
|
|
5c620870c1 | ||
|
|
110a9bc31e | ||
|
|
3af255baeb | ||
|
|
d13b6102c1 | ||
|
|
4a4523a1f0 | ||
|
|
2733d4fd7e | ||
|
|
cbe49b2db5 | ||
|
|
b92248ec47 | ||
|
|
018bb6ef9a | ||
|
|
85fd507004 | ||
|
|
0f9e1886cb | ||
|
|
d8f3838c50 | ||
|
|
d3881ac19d | ||
|
|
e5be1a527e |
@@ -162,26 +162,46 @@ const char *ast_node_id_to_cstr(node_id_t id) {
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Helper function to print a single AST node with indentation
|
||||
*
|
||||
* @param node The node to print
|
||||
* @param indent Current indentation level
|
||||
*/
|
||||
static void ast_node_print_internal(ast_node_t *node, int indent) {
|
||||
if (node == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Print indentation
|
||||
for (int i = 0; i < indent; i++) {
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
// Print node type
|
||||
printf("%s", ast_node_id_to_cstr(node->id));
|
||||
|
||||
// Print token value if available
|
||||
if (node->token_entry && node->token_entry->token.value) {
|
||||
printf(" \"%s\"", node->token_entry->token.value);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Recursively print all children with increased indentation
|
||||
for (size_t i = 0; i < node->len; i++) {
|
||||
ast_node_print_internal(node->children[i], indent + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prints an AST starting from the given node
|
||||
*
|
||||
* Prints a representation of the AST with indentation to show structure.
|
||||
* Each node's type is shown, and if a node has an associated token value,
|
||||
* that value is printed in quotes.
|
||||
*
|
||||
* @param node The root node of the AST to print
|
||||
*/
|
||||
void ast_node_print(ast_node_t *node) {
|
||||
ast_node_print_internal(node, 0);
|
||||
}
|
||||
|
||||
@@ -106,15 +106,7 @@ void ast_node_free(ast_node_t *node);
|
||||
*/
|
||||
error_t *ast_node_add_child(ast_node_t *node, ast_node_t *child);
|
||||
|
||||
/**
|
||||
* @brief Prints an AST starting from the given node
|
||||
*
|
||||
* Prints a representation of the AST with indentation to show structure.
|
||||
* Each node's type is shown, and if a node has an associated token value,
|
||||
* that value is printed in quotes.
|
||||
*
|
||||
* @param node The root node of the AST to print
|
||||
*/
|
||||
const char *ast_node_id_to_cstr(node_id_t id);
|
||||
void ast_node_print(ast_node_t *node);
|
||||
|
||||
#endif // INCLUDE_SRC_AST_H_
|
||||
|
||||
Reference in New Issue
Block a user