lang: add internal debugging interface
This commit is contained in:
44
lang/internal.c
Normal file
44
lang/internal.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include "lex.h"
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <ivy/lang/internal.h>
|
||||
#include <blue/object/number.h>
|
||||
|
||||
static void print_symbol_node(struct ivy_lexer_symbol_node *node, int depth)
|
||||
{
|
||||
for (int i = 0; i < depth; i++) {
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
|
||||
printf("%c", node->s_char);
|
||||
|
||||
if (node->s_id != IVY_SYM_NONE) {
|
||||
printf(" (%s)", ivy_symbol_to_string(node->s_id));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
b_queue_iterator it;
|
||||
b_queue_foreach (&it, &node->s_children) {
|
||||
struct ivy_lexer_symbol_node *child = b_unbox(
|
||||
struct ivy_lexer_symbol_node, it.entry, s_entry);
|
||||
|
||||
print_symbol_node(child, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void internal_lexer_print_symbol_tree(struct ivy_lexer* lex)
|
||||
{
|
||||
print_symbol_node(lex->lex_sym_tree, -1);
|
||||
}
|
||||
|
||||
void internal_lexer_print_keyword_dict(struct ivy_lexer* lex)
|
||||
{
|
||||
b_dict_iterator it = {0};
|
||||
b_dict_foreach(&it, lex->lex_keywords) {
|
||||
const char *kw_name = it.key;
|
||||
enum ivy_keyword kw_id = b_number_get_int(B_NUMBER(it.value));
|
||||
|
||||
printf("[%s] = '%s'\n", ivy_keyword_to_string(kw_id), kw_name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user