feat(parser): implementing all redirection types -- WIP

This commit is contained in:
Matteo Flebus 2026-01-26 19:00:20 +01:00
parent d707c6180b
commit 666517e3c1
3 changed files with 29 additions and 1 deletions

View file

@ -5,6 +5,7 @@
#include <stdlib.h>
#include "grammar_basic.h"
#include "../lexer/lexer.h"
// === Static variables
@ -84,11 +85,30 @@ static void add_first_redir(enum rule rule)
add_first(rule, TOKEN_REDIR_LEFT_RIGHT);
add_first(rule, TOKEN_REDIR_DOUBLE_RIGHT);
add_first(rule, TOKEN_REDIR_LEFT_AMP);
add_first(rule, TOKEN_REDIR_RIGHT_AMP);
add_first(rule, TOKEN_REDIR_RIGHT_PIPE);
}
// === Functions
bool is_token_redir(struct token *token)
{
switch (token->type)
{
case TOKEN_REDIR_LEFT:
case TOKEN_REDIR_RIGHT:
case TOKEN_REDIR_LEFT_RIGHT:
case TOKEN_REDIR_DOUBLE_RIGHT:
case TOKEN_REDIR_LEFT_AMP:
case TOKEN_REDIR_RIGHT_AMP:
case TOKEN_REDIR_RIGHT_PIPE:
return true;
default:
return false;
}
}
bool grammar_init(void)
{
// Initialize the firsts map
@ -196,7 +216,9 @@ struct ast *parse_input(struct lexer_context *ctx)
if (token->type == TOKEN_NEWLINE || token->type == TOKEN_EOF)
{
if (token->type == TOKEN_NEWLINE)
{
POP_TOKEN();
}
return ast;
}