lang: replace stack-based parser with a recursive parser

This commit is contained in:
2026-04-06 18:25:43 +01:00
parent 3a549aa6df
commit b904813cef
77 changed files with 2984 additions and 6499 deletions
+49
View File
@@ -0,0 +1,49 @@
#include "ctx.h"
#include <ivy/lang/ast.h>
bool parse_package_import(struct ivy_parser *parser, struct ivy_ast_node **out)
{
if (!parse_keyword(parser, IVY_KW_USE)) {
parse_trace(
NULL, "expected `use` before package import statement");
return false;
}
struct ivy_ast_unit_import_node *unit_import
= create_node(IVY_AST_UNIT_IMPORT);
struct ivy_token *tok = NULL;
if (!parse_word(parser, &tok)) {
parse_trace(NULL, "expected word after `use` keyword");
return false;
}
fx_queue_push_back(&unit_import->n_ident, &tok->t_entry);
while (1) {
if (parse_linefeed(parser)) {
break;
}
if (!parse_symbol(parser, IVY_SYM_DOT)) {
parse_trace(
NULL,
"expected linefeed or `.` after package "
"identifier word");
destroy_node(unit_import);
return false;
}
if (!parse_word(parser, &tok)) {
parse_trace(NULL, "expected word after `use` keyword");
destroy_node(unit_import);
return false;
}
fx_queue_push_back(&unit_import->n_ident, &tok->t_entry);
}
*out = generic_node(unit_import);
return true;
}