ref: split parser into separate files

This commit is contained in:
samsonium
2026-10-29 00:08:44 +03:00
parent 62b0030e4a
commit 8c90d54782
27 changed files with 1444 additions and 1307 deletions
+48
View File
@@ -0,0 +1,48 @@
#include <compiler/fzl_parser.h>
#include <compiler/internals/parser.h>
#include <stdio.h>
// Statement parsing
fzl_node_t *pa_statement(fzl_parser_t *parser)
{
if (!peek(parser))
return NULL;
fzl_node_t *res = NULL;
if (is(parser, FZL_TOKTYPE_CLASS))
return pa_class(parser);
else if (is(parser, FZL_TOKTYPE_FUNCTION))
return pa_function(parser);
else if (is(parser, FZL_TOKTYPE_RETURN))
res = pa_return(parser);
else if (is(parser, FZL_TOKTYPE_IF))
return pa_if(parser);
else if (is(parser, FZL_TOKTYPE_LBRACE))
return pa_block(parser);
else if (is(parser, FZL_TOKTYPE_FOR) || is(parser, FZL_TOKTYPE_WHILE))
return pa_loop(parser);
else if (is(parser, FZL_TOKTYPE_BREAK))
res = pa_break(parser);
if (!res)
res = pa_expression(parser);
if (!res)
{
fzl_freeast(res);
return NULL;
}
if (!is(parser, FZL_TOKTYPE_SEMICOLON))
{
fzl_freeast(res);
snprintf(plast_err, sizeof(plast_err), "'%s': missing ';' at %ld:%ld",
last_known_tok->filename, last_known_tok->ln, last_known_tok->cn);
return NULL;
}
while (is(parser, FZL_TOKTYPE_SEMICOLON))
consume(parser);
return res;
}