diff --git a/src/parser/grammar_basic.c b/src/parser/grammar_basic.c index d86abb6..92113fe 100644 --- a/src/parser/grammar_basic.c +++ b/src/parser/grammar_basic.c @@ -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);