feat(parser): ast_subshell

This commit is contained in:
matteo 2026-01-31 19:45:40 +01:00
parent 19addf8e6f
commit 3e42b6fd00

View file

@ -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);