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 token *token = PEEK_TOKEN();
|
||||||
struct ast *result = NULL;
|
struct ast *result = NULL;
|
||||||
|
|
||||||
// Grouping
|
// '{'
|
||||||
// '(' or '{'
|
if (token->type == TOKEN_LEFT_BRACKET)
|
||||||
if (token->type == TOKEN_LEFT_BRACKET || token->type == TOKEN_LEFT_PAREN)
|
|
||||||
{
|
{
|
||||||
POP_TOKEN();
|
POP_TOKEN();
|
||||||
result = parse_compound_list(ctx);
|
result = parse_compound_list(ctx);
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// ')' or '}'
|
// '}'
|
||||||
token = PEEK_TOKEN();
|
token = PEEK_TOKEN();
|
||||||
if (token->type == TOKEN_LEFT_BRACKET
|
if (token->type == TOKEN_LEFT_BRACKET)
|
||||||
|| token->type == TOKEN_LEFT_PAREN)
|
|
||||||
{
|
{
|
||||||
ast_free(&result);
|
ast_free(&result);
|
||||||
perror("Syntax error: bracket/parenthesis mismatch");
|
perror("Syntax error: bracket mismatch");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
POP_TOKEN();
|
POP_TOKEN();
|
||||||
return result;
|
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))
|
else if (is_first(*token, RULE_IF))
|
||||||
{
|
{
|
||||||
return parse_if_rule(ctx);
|
return parse_if_rule(ctx);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue