fix(parser): 3098750984535 compilations errors in parsing_utils

This commit is contained in:
Matteo Flebus 2026-01-19 19:15:28 +01:00
parent 5d87e87f2e
commit c1f1a2fc37

View file

@ -1,9 +1,12 @@
#define _POSIX_C_SOURCE 200809L
// === Includes
#include "parsing_utils.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "lexer/lexer.h"
#include "utils/ast/ast.h"
@ -11,7 +14,7 @@
// === Static functions
/* Returns true if c is a command terminator, false otherwise
*/
*/
static bool isterminator(struct token *token)
{
if (token == NULL)
@ -19,17 +22,20 @@ static bool isterminator(struct token *token)
switch (token->type)
{
case TOKEN_NEWLINE:
case TOKEN_SEMICOLON:
case TOKEN_EOF:
return true;
default:
return false;
case TOKEN_NEWLINE:
case TOKEN_SEMICOLON:
case TOKEN_EOF:
return true;
default:
return false;
}
}
/* @brief: returns true if token is an end of list indicator.
* @warning: not used
*/
/*
static bool is_end_of_list(struct token *token)
{
if (token == NULL)
@ -37,13 +43,14 @@ static bool is_end_of_list(struct token *token)
switch (token->type)
{
case TOKEN_NEWLINE:
case TOKEN_EOF:
return true;
default:
return false;
case TOKEN_NEWLINE:
case TOKEN_EOF:
return true;
default:
return false;
}
}
*/
// === Functions
@ -150,7 +157,7 @@ struct ast *parse_if_rule(void)
if (token->type != TOKEN_IF)
{
puts("Internal error: expected a if rule but token has different "
"type");
"type");
return NULL;
}
@ -215,8 +222,10 @@ struct ast *parse_compound_list(void)
struct token *token = PEEK_TOKEN();
// Skip newlines
while (token == TOKEN_NEWLINE)
while (token->type == TOKEN_NEWLINE)
{
token = POP_TOKEN();
}
// and_or
current_cmd = parse_and_or();
@ -226,13 +235,15 @@ struct ast *parse_compound_list(void)
// Following commands
token = PEEK_TOKEN();
while (token->type == TOKEN_SEMICOLON || token->type TOKEN_NEWLINE)
while (token->type == TOKEN_SEMICOLON || token->type == TOKEN_NEWLINE)
{
POP_TOKEN();
// Skip newlines
while (token == TOKEN_NEWLINE)
while (token->type == TOKEN_NEWLINE)
{
token = POP_TOKEN();
}
// and_or
current_cmd = parse_and_or();
@ -245,11 +256,15 @@ struct ast *parse_compound_list(void)
// Eventual semicolons
if (token->type == TOKEN_SEMICOLON)
{
token = POP_TOKEN();
}
// Skip newlines
while (token == TOKEN_NEWLINE)
while (token->type == TOKEN_NEWLINE)
{
token = POP_TOKEN();
}
struct ast *result = ast_create_list(result_list);
@ -281,7 +296,7 @@ struct ast *parse_else_clause(void)
// Eventual else clause (recursive)
struct ast *else_content = NULL;
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();
}