fix: restored progress from the old parser branch

This commit is contained in:
Gu://em_ 2026-01-13 16:53:25 +01:00
parent 9923ebc677
commit 7b773641a1

View file

@ -1,12 +1,67 @@
#include "parser.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;