fix: random fixes
This commit is contained in:
parent
3ee4a0b9ca
commit
787b1aed35
3 changed files with 35 additions and 8 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue