Files
ivy/lang/internal.c

53 lines
1.2 KiB
C
Raw Normal View History

2024-11-19 15:22:39 +00:00
#include "lex.h"
2025-11-06 10:38:32 +00:00
2026-03-16 14:07:33 +00:00
#include <fx/ds/number.h>
#include <fx/term/print.h>
2025-11-06 10:38:32 +00:00
#include <ivy/lang/internal.h>
#include <ivy/lang/lex.h>
#include <stdio.h>
2024-11-19 15:22:39 +00:00
static void print_symbol_node(struct ivy_lexer_symbol_node *node, int depth)
{
for (int i = 0; i < depth; i++) {
fputs(" ", stdout);
}
2026-03-16 14:07:33 +00:00
fx_printf("[cyan]%c[reset]", node->s_char);
2024-11-19 15:22:39 +00:00
if (node->s_def != NULL) {
2026-03-16 14:07:33 +00:00
fx_printf(
" ([magenta]%s[reset])",
ivy_symbol_to_string(node->s_def->id));
2024-11-19 15:22:39 +00:00
}
2026-03-16 14:07:33 +00:00
fx_printf("\n");
2024-11-19 15:22:39 +00:00
2026-03-16 14:07:33 +00:00
fx_queue_entry *entry = fx_queue_first(&node->s_children);
2025-11-06 10:38:32 +00:00
while (entry) {
struct ivy_lexer_symbol_node *child
2026-03-16 14:07:33 +00:00
= fx_unbox(struct ivy_lexer_symbol_node, entry, s_entry);
2024-11-19 15:22:39 +00:00
print_symbol_node(child, depth + 1);
2026-03-16 14:07:33 +00:00
entry = fx_queue_next(entry);
2024-11-19 15:22:39 +00:00
}
}
2025-11-06 10:38:32 +00:00
void internal_lexer_print_symbol_tree(struct ivy_lexer *lex)
2024-11-19 15:22:39 +00:00
{
print_symbol_node(lex->lex_sym_tree, -1);
}
2025-11-06 10:38:32 +00:00
void internal_lexer_print_keyword_dict(struct ivy_lexer *lex)
2024-11-19 15:22:39 +00:00
{
2026-03-16 14:07:33 +00:00
fx_iterator *it = fx_iterator_begin(lex->lex_keywords);
fx_foreach_ptr(fx_dict_item, item, it)
2025-11-06 10:38:32 +00:00
{
2026-03-16 14:07:33 +00:00
const fx_string *kw_name = item->key;
enum ivy_keyword kw_id = fx_number_get_int(item->value);
2025-11-06 10:38:32 +00:00
2026-03-16 14:07:33 +00:00
fx_printf(
2025-11-06 10:38:32 +00:00
"([magenta]%s[reset]) = [green]%s[reset]\n",
2026-03-16 14:07:33 +00:00
ivy_keyword_to_string(kw_id), fx_string_ptr(kw_name));
2024-11-19 15:22:39 +00:00
}
2025-11-06 10:38:32 +00:00
}