fix(parser): adapting to new lexer

This commit is contained in:
Matteo Flebus 2026-01-20 20:06:25 +01:00
parent bf929d413f
commit d5a1ec3ca6

View file

@ -56,7 +56,7 @@ static bool is_end_of_list(struct token *token)
struct ast *parse_input(struct lexer_context *ctx) struct ast *parse_input(struct lexer_context *ctx)
{ {
return parse_list(); return parse_list(ctx);
} }
struct ast *parse_list(struct lexer_context *ctx) struct ast *parse_list(struct lexer_context *ctx)
@ -79,7 +79,7 @@ struct ast *parse_list(struct lexer_context *ctx)
token = POP_TOKEN(); token = POP_TOKEN();
if (!isterminator(token)) // Follow(list) if (!isterminator(token)) // Follow(list)
{ {
current_node = parse_and_or(); current_node = parse_and_or(ctx);
if (current_node == NULL) if (current_node == NULL)
{ {
// TODO free list // TODO free list
@ -97,12 +97,12 @@ struct ast *parse_list(struct lexer_context *ctx)
struct ast *parse_and_or(struct lexer_context *ctx) struct ast *parse_and_or(struct lexer_context *ctx)
{ {
return parse_pipeline(); return parse_pipeline(ctx);
} }
struct ast *parse_pipeline(struct lexer_context *ctx) struct ast *parse_pipeline(struct lexer_context *ctx)
{ {
return parse_command(); return parse_command(ctx);
} }
struct ast *parse_command(struct lexer_context *ctx) struct ast *parse_command(struct lexer_context *ctx)
@ -111,11 +111,11 @@ struct ast *parse_command(struct lexer_context *ctx)
if (token->type == TOKEN_WORD) if (token->type == TOKEN_WORD)
{ {
return parse_simple_command(); return parse_simple_command(ctx);
} }
else if (token->type == TOKEN_IF) else if (token->type == TOKEN_IF)
{ {
return parse_shell_command(); return parse_shell_command(ctx);
} }
else else
{ {
@ -135,7 +135,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
while (token->type == TOKEN_WORD) while (token->type == TOKEN_WORD)
{ {
token = pop_token(); token = pop_token(ctx);
if (token == NULL) if (token == NULL)
{ {
// TODO free // TODO free
@ -150,7 +150,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
return NULL; return NULL;
} }
command_elements = list_append(command_elements, word); command_elements = list_append(command_elements, word);
token = peek_token(); token = peek_token(ctx);
if (token == NULL) if (token == NULL)
{ {
// TODO free // TODO free
@ -168,7 +168,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx)
struct ast *parse_shell_command(struct lexer_context *ctx) struct ast *parse_shell_command(struct lexer_context *ctx)
{ {
return parse_if_rule(); return parse_if_rule(ctx);
} }
struct ast *parse_if_rule(struct lexer_context *ctx) struct ast *parse_if_rule(struct lexer_context *ctx)
@ -183,7 +183,7 @@ struct ast *parse_if_rule(struct lexer_context *ctx)
} }
// Condition content // Condition content
struct ast *condition_content = parse_compound_list(); struct ast *condition_content = parse_compound_list(ctx);
// Then keyword // Then keyword
token = POP_TOKEN(); token = POP_TOKEN();
@ -195,7 +195,7 @@ struct ast *parse_if_rule(struct lexer_context *ctx)
} }
// Then content // Then content
struct ast *then_content = parse_compound_list(); struct ast *then_content = parse_compound_list(ctx);
if (then_content == NULL) if (then_content == NULL)
{ {
ast_free(&condition_content); ast_free(&condition_content);
@ -204,7 +204,7 @@ struct ast *parse_if_rule(struct lexer_context *ctx)
} }
// Eventual else/elif clause(s) // Eventual else/elif clause(s)
struct ast *else_content = parse_else_clause(); struct ast *else_content = parse_else_clause(ctx);
if (else_content == NULL) if (else_content == NULL)
{ {
ast_free(&condition_content); ast_free(&condition_content);
@ -249,7 +249,7 @@ struct ast *parse_compound_list(struct lexer_context *ctx)
} }
// and_or // and_or
current_cmd = parse_and_or(); current_cmd = parse_and_or(ctx);
if (current_cmd == NULL) if (current_cmd == NULL)
return NULL; return NULL;
list_append(result_list, current_cmd); list_append(result_list, current_cmd);
@ -267,7 +267,7 @@ struct ast *parse_compound_list(struct lexer_context *ctx)
} }
// and_or // and_or
current_cmd = parse_and_or(); current_cmd = parse_and_or(ctx);
if (current_cmd == NULL) if (current_cmd == NULL)
return NULL; return NULL;
list_append(result_list, current_cmd); list_append(result_list, current_cmd);
@ -300,7 +300,7 @@ struct ast *parse_else_clause(struct lexer_context *ctx)
{ {
// Condition // Condition
token = POP_TOKEN(); token = POP_TOKEN();
struct ast *condition = parse_compound_list(); struct ast *condition = parse_compound_list(ctx);
// 'then' // 'then'
token = POP_TOKEN(); token = POP_TOKEN();
@ -311,14 +311,14 @@ struct ast *parse_else_clause(struct lexer_context *ctx)
} }
// Then clause // Then clause
struct ast *then_content = parse_compound_list(); struct ast *then_content = parse_compound_list(ctx);
// Eventual else clause (recursive) // Eventual else clause (recursive)
struct ast *else_content = NULL; struct ast *else_content = NULL;
token = PEEK_TOKEN(); token = PEEK_TOKEN();
if (token->type == TOKEN_ELSE || token->type == TOKEN_ELIF) if (token->type == TOKEN_ELSE || token->type == TOKEN_ELIF)
{ {
else_content = parse_else_clause(); else_content = parse_else_clause(ctx);
} }
struct ast *result = struct ast *result =
@ -332,12 +332,12 @@ struct ast *parse_else_clause(struct lexer_context *ctx)
if (token->type == TOKEN_ELSE) if (token->type == TOKEN_ELSE)
{ {
result = parse_compound_list(); result = parse_compound_list(ctx);
token = POP_TOKEN(); // Forward token = POP_TOKEN(); // Forward
} }
if (result == NULL) if (result == NULL)
result = ast_create_void(); result = ast_create_void(ctx);
return result; return result;
} }