feat(parser): ast_subshell
This commit is contained in:
parent
19addf8e6f
commit
3e42b6fd00
1 changed files with 24 additions and 7 deletions
|
|
@ -372,28 +372,45 @@ struct ast *parse_shell_command(struct lexer_context *ctx)
|
|||
struct token *token = PEEK_TOKEN();
|
||||
struct ast *result = NULL;
|
||||
|
||||
// Grouping
|
||||
// '(' or '{'
|
||||
if (token->type == TOKEN_LEFT_BRACKET || token->type == TOKEN_LEFT_PAREN)
|
||||
// '{'
|
||||
if (token->type == TOKEN_LEFT_BRACKET)
|
||||
{
|
||||
POP_TOKEN();
|
||||
result = parse_compound_list(ctx);
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
|
||||
// ')' or '}'
|
||||
// '}'
|
||||
token = PEEK_TOKEN();
|
||||
if (token->type == TOKEN_LEFT_BRACKET
|
||||
|| token->type == TOKEN_LEFT_PAREN)
|
||||
if (token->type == TOKEN_LEFT_BRACKET)
|
||||
{
|
||||
ast_free(&result);
|
||||
perror("Syntax error: bracket/parenthesis mismatch");
|
||||
perror("Syntax error: bracket mismatch");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
POP_TOKEN();
|
||||
return result;
|
||||
}
|
||||
// '('
|
||||
else if (token->type == TOKEN_LEFT_PAREN)
|
||||
{
|
||||
POP_TOKEN();
|
||||
result = parse_compound_list(ctx);
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
|
||||
// ')'
|
||||
token = PEEK_TOKEN();
|
||||
if (token->type == TOKEN_LEFT_PAREN)
|
||||
{
|
||||
ast_free(&result);
|
||||
perror("Syntax error: parenthesis mismatch");
|
||||
return NULL;
|
||||
}
|
||||
POP_TOKEN();
|
||||
return ast_create_subshell(result);
|
||||
}
|
||||
else if (is_first(*token, RULE_IF))
|
||||
{
|
||||
return parse_if_rule(ctx);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue