From 7b773641a148d14ee815f9cb588ca2e639083741 Mon Sep 17 00:00:00 2001 From: "Gu://em_" Date: Tue, 13 Jan 2026 16:53:25 +0100 Subject: [PATCH] fix: restored progress from the old parser branch --- src/parser/parser.c | 57 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/parser/parser.c b/src/parser/parser.c index 30cecdd..9d2cf10 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -1,12 +1,67 @@ #include "parser.h" +#include #include +#include +#include +#include + +#include "lexer/lexer.h" +#include "utils/lists/lists.h" + +// === Static functions + +/* Returns true if c is a command terminator, false otherwise + */ +static bool isterminator(char c) +{ + switch (c) + { + case '\n': + case ';': + case EOF: + return true; + default: + return false; + } +} + +/* Parses a simple list of words (command and arguments) + * and returns the resulting ast + */ +static struct ast *parse_simple_command(void) +{ + struct list *cmd_elements = NULL; + char *token = get_token(); + if (token == NULL) // just in case ? + return NULL; + + while (token != NULL && !isterminator(token[0])) + { + cmd_elements = list_append(cmd_elements, token); + token = get_token(); + } + + if (token == NULL) + return NULL; // TODO handle error + + struct ast *result = ast_create_cmd(cmd_elements); + return result; +} + +// === Functions struct ast *get_ast() { - return NULL; + struct ast *result = NULL; + struct ast *current_node = NULL; + + // char *token = get_token(); + + return result; } +// TODO struct ast *get_ast_str(char *command) { (void)command;