feat: finished the new firsts system and began supporting redirections
This commit is contained in:
parent
32f56beb6b
commit
3ee4a0b9ca
4 changed files with 134 additions and 44 deletions
|
|
@ -43,15 +43,15 @@ struct ast *parse_list(struct lexer_context *ctx)
|
|||
while (token->type == TOKEN_SEMICOLON)
|
||||
{
|
||||
token = POP_TOKEN();
|
||||
current_node = parse_and_or(ctx);
|
||||
if (current_node == NULL)
|
||||
{
|
||||
// TODO free list
|
||||
// There must be a function for that
|
||||
return NULL;
|
||||
}
|
||||
result_list = list_append(result_list, current_node);
|
||||
token = PEEK_TOKEN();
|
||||
if (is_first(*token, RULE_AND_OR))
|
||||
{
|
||||
current_node = parse_and_or(ctx);
|
||||
if (current_node == NULL)
|
||||
return NULL;
|
||||
result_list = list_append(result_list, current_node);
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
}
|
||||
|
||||
return ast_create_list(result_list);
|
||||
|
|
@ -138,7 +138,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
|
|||
token = PEEK_TOKEN();
|
||||
|
||||
// Eventual elements
|
||||
while (token->type == TOKEN_WORD)
|
||||
while (is_first(*token, RULE_ELEMENT))
|
||||
{
|
||||
// Get element
|
||||
struct ast *element = parse_element(ctx);
|
||||
|
|
@ -170,7 +170,6 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
|
|||
}
|
||||
|
||||
// Forward
|
||||
POP_TOKEN();
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
||||
|
|
@ -189,9 +188,8 @@ struct ast *parse_element(struct lexer_context *ctx)
|
|||
struct token *token = PEEK_TOKEN();
|
||||
if (token->type == TOKEN_WORD)
|
||||
{
|
||||
// TODO
|
||||
puts("NOT IMPLEMENTED");
|
||||
return NULL;
|
||||
token = POP_TOKEN();
|
||||
return ast_create_word(token->data);
|
||||
}
|
||||
else if (token->type == TOKEN_IONUMBER || token->type == TOKEN_REDIRECTION)
|
||||
{
|
||||
|
|
@ -310,11 +308,14 @@ struct ast *parse_compound_list(struct lexer_context *ctx)
|
|||
}
|
||||
|
||||
// And/or
|
||||
current_cmd = parse_and_or(ctx);
|
||||
if (current_cmd == NULL)
|
||||
return NULL;
|
||||
result_list = list_append(result_list, current_cmd);
|
||||
|
||||
if (is_first(*token, RULE_AND_OR))
|
||||
{
|
||||
current_cmd = parse_and_or(ctx);
|
||||
if (current_cmd == NULL)
|
||||
return NULL;
|
||||
result_list = list_append(result_list, current_cmd);
|
||||
}
|
||||
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue