lang: ast: suppress debug output by default

This commit is contained in:
2024-12-05 19:37:58 +00:00
parent c0a90f40b5
commit 9a4b074381
3 changed files with 48 additions and 22 deletions

View File

@@ -9,16 +9,18 @@
#include <stdlib.h>
#include <string.h>
#ifdef IVY_LANG_DEBUG
static void print_state_stack(struct ivy_parser *parser)
{
b_queue_iterator it = {0};
b_queue_foreach (&it, &parser->p_state) {
struct parser_state *state
= b_unbox(struct parser_state, it.entry, s_entry);
printf(" %s\n",
debug_printf(" %s\n",
ivy_ast_node_type_to_string(state->s_node->n_type));
}
}
#endif
enum ivy_status ivy_parser_create(struct ivy_parser **parser)
{
@@ -60,9 +62,10 @@ enum ivy_status ivy_parser_push_token(
struct token_parse_result result = func(parser, tok);
parser->p_status = result.r_status;
printf("states (after token)\n");
#ifdef IVY_LANG_DEBUG
debug_printf("states (after token)\n");
print_state_stack(parser);
#endif
if (result.r_flags & PARSE_REPEAT_TOKEN) {
continue;
}
@@ -144,8 +147,10 @@ struct parser_state *parser_push_state(
node_type->n_init_state(parser, state, arg);
}
printf("states (after push)\n");
#ifdef IVY_LANG_DEBUG
debug_printf("states (after push)\n");
print_state_stack(parser);
#endif
return state;
}
@@ -165,8 +170,10 @@ void parser_pop_state(struct ivy_parser *parser, enum pop_state_flags flags)
free(state);
printf("states (after pop)\n");
#ifdef IVY_LANG_DEBUG
debug_printf("states (after pop)\n");
print_state_stack(parser);
#endif
}
void parser_replace_current_node(