feat: implement extern block reading and parsing

This commit is contained in:
samsonium
2026-10-29 22:13:28 +03:00
parent 0448be0d38
commit f769313169
13 changed files with 719 additions and 3 deletions
+38
View File
@@ -0,0 +1,38 @@
#include <compiler/fzl_parser.h>
#include <compiler/fzl_token.h>
#include <compiler/internals/parser.h>
#include <stdio.h>
// Parse reference definition
fzl_node_t *pa_ref(fzl_parser_t *parser)
{
if (!parser || !peek(parser))
return NULL;
fzl_token_t *tok = consume(parser);
if (!tok || tok->type != FZL_TOKTYPE_REFERENCE)
{
snprintf(plast_err, sizeof(plast_err),
"'%s':%zu:%zu => expected 'ref' keyword", last_known_tok->filename,
last_known_tok->ln, last_known_tok->cn);
return NULL;
}
fzl_token_t *name = consume(parser);
if (!name || name->type != FZL_TOKTYPE_NAME)
{
snprintf(plast_err, sizeof(plast_err),
"'%s':%zu:%zu => expected name after 'ref'",
last_known_tok->filename, last_known_tok->ln, last_known_tok->cn);
return NULL;
}
fzl_node_t *node = fzl_mknode(FZL_NODETYPE_REFERENCE, name);
if (!node)
{
snprintf(plast_err, sizeof(plast_err), "out of memory");
return NULL;
}
return node;
}