Files
ivy/lang/parse/package-import.c
T

50 lines
1.0 KiB
C
Raw Normal View History

#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;
}