fix(parser): 3098750984535 compilations errors in parsing_utils
This commit is contained in:
parent
5d87e87f2e
commit
c1f1a2fc37
1 changed files with 35 additions and 20 deletions
|
|
@ -1,9 +1,12 @@
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
|
||||||
// === Includes
|
// === Includes
|
||||||
#include "parsing_utils.h"
|
#include "parsing_utils.h"
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "lexer/lexer.h"
|
#include "lexer/lexer.h"
|
||||||
#include "utils/ast/ast.h"
|
#include "utils/ast/ast.h"
|
||||||
|
|
@ -11,7 +14,7 @@
|
||||||
// === Static functions
|
// === Static functions
|
||||||
|
|
||||||
/* Returns true if c is a command terminator, false otherwise
|
/* Returns true if c is a command terminator, false otherwise
|
||||||
*/
|
*/
|
||||||
static bool isterminator(struct token *token)
|
static bool isterminator(struct token *token)
|
||||||
{
|
{
|
||||||
if (token == NULL)
|
if (token == NULL)
|
||||||
|
|
@ -19,17 +22,20 @@ static bool isterminator(struct token *token)
|
||||||
|
|
||||||
switch (token->type)
|
switch (token->type)
|
||||||
{
|
{
|
||||||
case TOKEN_NEWLINE:
|
case TOKEN_NEWLINE:
|
||||||
case TOKEN_SEMICOLON:
|
case TOKEN_SEMICOLON:
|
||||||
case TOKEN_EOF:
|
case TOKEN_EOF:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @brief: returns true if token is an end of list indicator.
|
/* @brief: returns true if token is an end of list indicator.
|
||||||
|
* @warning: not used
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
static bool is_end_of_list(struct token *token)
|
static bool is_end_of_list(struct token *token)
|
||||||
{
|
{
|
||||||
if (token == NULL)
|
if (token == NULL)
|
||||||
|
|
@ -37,13 +43,14 @@ static bool is_end_of_list(struct token *token)
|
||||||
|
|
||||||
switch (token->type)
|
switch (token->type)
|
||||||
{
|
{
|
||||||
case TOKEN_NEWLINE:
|
case TOKEN_NEWLINE:
|
||||||
case TOKEN_EOF:
|
case TOKEN_EOF:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// === Functions
|
// === Functions
|
||||||
|
|
||||||
|
|
@ -150,7 +157,7 @@ struct ast *parse_if_rule(void)
|
||||||
if (token->type != TOKEN_IF)
|
if (token->type != TOKEN_IF)
|
||||||
{
|
{
|
||||||
puts("Internal error: expected a if rule but token has different "
|
puts("Internal error: expected a if rule but token has different "
|
||||||
"type");
|
"type");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -215,24 +222,28 @@ struct ast *parse_compound_list(void)
|
||||||
struct token *token = PEEK_TOKEN();
|
struct token *token = PEEK_TOKEN();
|
||||||
|
|
||||||
// Skip newlines
|
// Skip newlines
|
||||||
while (token == TOKEN_NEWLINE)
|
while (token->type == TOKEN_NEWLINE)
|
||||||
|
{
|
||||||
token = POP_TOKEN();
|
token = POP_TOKEN();
|
||||||
|
}
|
||||||
|
|
||||||
// and_or
|
// and_or
|
||||||
current_cmd = parse_and_or();
|
current_cmd = parse_and_or();
|
||||||
if (current_cmd == NULL)
|
if (current_cmd == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
list_append(result_list, current_cmd);
|
list_append(result_list, current_cmd);
|
||||||
|
|
||||||
// Following commands
|
// Following commands
|
||||||
token = PEEK_TOKEN();
|
token = PEEK_TOKEN();
|
||||||
while (token->type == TOKEN_SEMICOLON || token->type TOKEN_NEWLINE)
|
while (token->type == TOKEN_SEMICOLON || token->type == TOKEN_NEWLINE)
|
||||||
{
|
{
|
||||||
POP_TOKEN();
|
POP_TOKEN();
|
||||||
|
|
||||||
// Skip newlines
|
// Skip newlines
|
||||||
while (token == TOKEN_NEWLINE)
|
while (token->type == TOKEN_NEWLINE)
|
||||||
|
{
|
||||||
token = POP_TOKEN();
|
token = POP_TOKEN();
|
||||||
|
}
|
||||||
|
|
||||||
// and_or
|
// and_or
|
||||||
current_cmd = parse_and_or();
|
current_cmd = parse_and_or();
|
||||||
|
|
@ -245,12 +256,16 @@ struct ast *parse_compound_list(void)
|
||||||
|
|
||||||
// Eventual semicolons
|
// Eventual semicolons
|
||||||
if (token->type == TOKEN_SEMICOLON)
|
if (token->type == TOKEN_SEMICOLON)
|
||||||
|
{
|
||||||
token = POP_TOKEN();
|
token = POP_TOKEN();
|
||||||
|
}
|
||||||
|
|
||||||
// Skip newlines
|
// Skip newlines
|
||||||
while (token == TOKEN_NEWLINE)
|
while (token->type == TOKEN_NEWLINE)
|
||||||
|
{
|
||||||
token = POP_TOKEN();
|
token = POP_TOKEN();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct ast *result = ast_create_list(result_list);
|
struct ast *result = ast_create_list(result_list);
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -281,7 +296,7 @@ struct ast *parse_else_clause(void)
|
||||||
// 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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue