fix: random fixes

This commit is contained in:
Gu://em_ 2026-01-24 16:48:21 +01:00
parent 3ee4a0b9ca
commit 787b1aed35
3 changed files with 35 additions and 8 deletions

View file

@ -166,5 +166,30 @@ bool is_first(struct token token, enum rule rule)
struct ast *parse_input(struct lexer_context *ctx)
{
return parse_list(ctx);
struct token *token = PEEK_TOKEN();
if (token->type == TOKEN_EOF)
return ast_create_list(NULL);
if (token->type == TOKEN_NEWLINE)
{
POP_TOKEN();
return ast_create_list(NULL);
}
struct ast *ast = parse_list(ctx);
if (ast == NULL)
return NULL;
token = PEEK_TOKEN();
if (token->type == TOKEN_NEWLINE || token->type == TOKEN_EOF)
{
if (token->type == TOKEN_NEWLINE)
POP_TOKEN();
return ast;
}
puts("Syntax error: expected newline or EOF after list");
ast_free(&ast);
return NULL;
}