diff --git a/src/parser/parsing_utils.c b/src/parser/parsing_utils.c index 487602d..544b311 100644 --- a/src/parser/parsing_utils.c +++ b/src/parser/parsing_utils.c @@ -1,9 +1,12 @@ +#define _POSIX_C_SOURCE 200809L + // === Includes #include "parsing_utils.h" #include #include #include +#include #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,24 +222,28 @@ 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(); if (current_cmd == NULL) return NULL; list_append(result_list, current_cmd); - + // 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,12 +256,16 @@ 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); return result; @@ -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(); }