feat(parser): assignments handled
This commit is contained in:
parent
fe3c4243c8
commit
28749a2992
2 changed files with 18 additions and 11 deletions
|
|
@ -173,7 +173,7 @@ struct ast *parse_command(struct lexer_context *ctx)
|
|||
* @return: NULL
|
||||
*/
|
||||
static void *err_simple_command(struct list *command_elements,
|
||||
struct list *redirections)
|
||||
struct list *redirections)
|
||||
{
|
||||
list_deep_destroy(command_elements);
|
||||
list_deep_destroy(redirections);
|
||||
|
|
@ -184,6 +184,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
|
|||
{
|
||||
struct list *command_elements = NULL;
|
||||
struct list *redirections = NULL; // list of redirection ASTs
|
||||
struct list *assignments = NULL;
|
||||
|
||||
bool has_prefix = false;
|
||||
struct token *token = PEEK_TOKEN();
|
||||
|
|
@ -192,12 +193,19 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
|
|||
has_prefix = true;
|
||||
while (is_first(*token, RULE_PREFIX))
|
||||
{
|
||||
struct ast *redir = parse_prefix(ctx);
|
||||
if (redir == NULL)
|
||||
struct ast *prefix = parse_prefix(ctx);
|
||||
if (prefix == NULL)
|
||||
{
|
||||
return err_simple_command(command_elements, redirections);
|
||||
}
|
||||
redirections = list_append(redirections, redir);
|
||||
if (prefix->type == AST_ASSIGNEMENT)
|
||||
{
|
||||
assignments = list_append(assignments, prefix)
|
||||
}
|
||||
else if (prefix->type == AST_REDIR)
|
||||
{
|
||||
redirections = list_append(redirections, prefix);
|
||||
}
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
}
|
||||
|
|
@ -250,8 +258,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
|
|||
else
|
||||
{
|
||||
perror("Internal error: unexpected return value from "
|
||||
"parse_element "
|
||||
"in parse_simple_command");
|
||||
"parse_element in parse_simple_command");
|
||||
return err_simple_command(command_elements, redirections);
|
||||
}
|
||||
|
||||
|
|
@ -260,9 +267,8 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
|
|||
}
|
||||
}
|
||||
|
||||
// Result
|
||||
// TODO handle assignements
|
||||
struct ast *result = ast_create_command(command_elements, redirections);
|
||||
struct ast *result =
|
||||
ast_create_command(command_elements, redirections, assignments);
|
||||
if (result == NULL)
|
||||
{
|
||||
return err_simple_command(command_elements, redirections);
|
||||
|
|
@ -297,7 +303,8 @@ struct ast *parse_shell_command(struct lexer_context *ctx)
|
|||
/* @brief: frees all the arguments. (helper func)
|
||||
* @return: NULL.
|
||||
*/
|
||||
static void *err_if_rule(struct ast **cond, struct ast **then_clause, struct ast **else_clause)
|
||||
static void *err_if_rule(struct ast **cond, struct ast **then_clause,
|
||||
struct ast **else_clause)
|
||||
{
|
||||
ast_free(cond);
|
||||
ast_free(then_clause);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue