feat(parser): implementing redirections...

This commit is contained in:
Matteo Flebus 2026-01-27 16:17:40 +01:00
parent d52f603eec
commit 7614370d00
2 changed files with 17 additions and 2 deletions

View file

@ -6,7 +6,19 @@
#include "grammar_basic.h" #include "grammar_basic.h"
bool static enum ast_redir_type redir_tok_to_ast_type(enum token_type tok_type)
{
switch(tok_type)
{
case TOKEN_REDIR_LEFT:
return AST_REDIR_TYPE_LESS;
case TOKEN_REDIR_RIGHT:
return AST_REDIR_TYPE_GREAT;
// TODO finish this
default:
return AST_REDIR_TYPE_NULL;
}
}
struct ast *parse_redirection(struct lexer_context *ctx) struct ast *parse_redirection(struct lexer_context *ctx)
{ {
@ -26,6 +38,8 @@ struct ast *parse_redirection(struct lexer_context *ctx)
return NULL; return NULL;
} }
// char *redir_op = strdup(token->data); // char *redir_op = strdup(token->data);
enum ast_redir_type redir_type = redir_tok_to_ast_type(token->type);
POP_TOKEN(); POP_TOKEN();
token = PEEK_TOKEN(); token = PEEK_TOKEN();
@ -38,7 +52,7 @@ struct ast *parse_redirection(struct lexer_context *ctx)
char *target = strdup(token->data); char *target = strdup(token->data);
POP_TOKEN(); POP_TOKEN();
return ast_create_redir(io_number, redir_op, target); return ast_create_redir(io_number, redir_type, target);
} }
struct ast *parse_prefix(struct lexer_context *ctx) struct ast *parse_prefix(struct lexer_context *ctx)

View file

@ -5,6 +5,7 @@
enum ast_redir_type enum ast_redir_type
{ {
AST_REDIR_TYPE_NULL,
AST_REDIR_TYPE_LESS, // < AST_REDIR_TYPE_LESS, // <
AST_REDIR_TYPE_GREAT, // > AST_REDIR_TYPE_GREAT, // >
AST_REDIR_TYPE_DLESS, // << AST_REDIR_TYPE_DLESS, // <<