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
|
* @return: NULL
|
||||||
*/
|
*/
|
||||||
static void *err_simple_command(struct list *command_elements,
|
static void *err_simple_command(struct list *command_elements,
|
||||||
struct list *redirections)
|
struct list *redirections)
|
||||||
{
|
{
|
||||||
list_deep_destroy(command_elements);
|
list_deep_destroy(command_elements);
|
||||||
list_deep_destroy(redirections);
|
list_deep_destroy(redirections);
|
||||||
|
|
@ -184,6 +184,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
|
||||||
{
|
{
|
||||||
struct list *command_elements = NULL;
|
struct list *command_elements = NULL;
|
||||||
struct list *redirections = NULL; // list of redirection ASTs
|
struct list *redirections = NULL; // list of redirection ASTs
|
||||||
|
struct list *assignments = NULL;
|
||||||
|
|
||||||
bool has_prefix = false;
|
bool has_prefix = false;
|
||||||
struct token *token = PEEK_TOKEN();
|
struct token *token = PEEK_TOKEN();
|
||||||
|
|
@ -192,12 +193,19 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
|
||||||
has_prefix = true;
|
has_prefix = true;
|
||||||
while (is_first(*token, RULE_PREFIX))
|
while (is_first(*token, RULE_PREFIX))
|
||||||
{
|
{
|
||||||
struct ast *redir = parse_prefix(ctx);
|
struct ast *prefix = parse_prefix(ctx);
|
||||||
if (redir == NULL)
|
if (prefix == NULL)
|
||||||
{
|
{
|
||||||
return err_simple_command(command_elements, redirections);
|
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();
|
token = PEEK_TOKEN();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -250,8 +258,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
perror("Internal error: unexpected return value from "
|
perror("Internal error: unexpected return value from "
|
||||||
"parse_element "
|
"parse_element in parse_simple_command");
|
||||||
"in parse_simple_command");
|
|
||||||
return err_simple_command(command_elements, redirections);
|
return err_simple_command(command_elements, redirections);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -260,9 +267,8 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Result
|
struct ast *result =
|
||||||
// TODO handle assignements
|
ast_create_command(command_elements, redirections, assignments);
|
||||||
struct ast *result = ast_create_command(command_elements, redirections);
|
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
{
|
{
|
||||||
return err_simple_command(command_elements, redirections);
|
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)
|
/* @brief: frees all the arguments. (helper func)
|
||||||
* @return: NULL.
|
* @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(cond);
|
||||||
ast_free(then_clause);
|
ast_free(then_clause);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue