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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,6 @@
|
|||
struct ast *parse_redirection(struct lexer_context *ctx)
|
||||
{
|
||||
struct token *token = PEEK_TOKEN();
|
||||
if (token->type == TOKEN_IONUMBER)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
int io_number = -1;
|
||||
if (token->type == TOKEN_IONUMBER)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -48,7 +48,11 @@ struct ast *parse_list(struct lexer_context *ctx)
|
|||
{
|
||||
current_node = parse_and_or(ctx);
|
||||
if (current_node == NULL)
|
||||
{
|
||||
struct ast *tmp = ast_create_list(result_list);
|
||||
ast_free(&tmp);
|
||||
return NULL;
|
||||
}
|
||||
result_list = list_append(result_list, current_node);
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
|
@ -60,9 +64,11 @@ struct ast *parse_list(struct lexer_context *ctx)
|
|||
struct ast *parse_and_or(struct lexer_context *ctx)
|
||||
{
|
||||
struct ast *result = parse_pipeline(ctx);
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
struct token *token = PEEK_TOKEN();
|
||||
|
||||
if (token->type == TOKEN_AND || token->type == TOKEN_OR)
|
||||
while (token->type == TOKEN_AND || token->type == TOKEN_OR)
|
||||
{
|
||||
// Set left part
|
||||
|
||||
|
|
@ -117,7 +123,8 @@ struct ast *parse_command(struct lexer_context *ctx)
|
|||
}
|
||||
else
|
||||
{
|
||||
return ast_create_void(); // TODO not sure what to do
|
||||
puts("Syntax error: expected command");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue