feat(parser): redirections
This commit is contained in:
parent
04ff7376eb
commit
8a5c589742
17 changed files with 78 additions and 108 deletions
|
|
@ -1,3 +1,5 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include "grammar_advanced.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
@ -8,23 +10,20 @@
|
|||
|
||||
static enum ast_redir_type redir_tok_to_ast_type(enum token_type tok_type)
|
||||
{
|
||||
switch(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;
|
||||
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)
|
||||
{
|
||||
(void)ctx;
|
||||
return NULL;
|
||||
/*
|
||||
struct token *token = PEEK_TOKEN();
|
||||
int io_number = -1;
|
||||
if (token->type == TOKEN_IONUMBER)
|
||||
|
|
@ -37,10 +36,9 @@ struct ast *parse_redirection(struct lexer_context *ctx)
|
|||
if (!is_token_redir(token))
|
||||
{
|
||||
perror("Syntax error: expected a redirection token but got something "
|
||||
"else");
|
||||
"else");
|
||||
return NULL;
|
||||
}
|
||||
// char *redir_op = strdup(token->data);
|
||||
|
||||
enum ast_redir_type redir_type = redir_tok_to_ast_type(token->type);
|
||||
POP_TOKEN();
|
||||
|
|
@ -49,14 +47,12 @@ struct ast *parse_redirection(struct lexer_context *ctx)
|
|||
if (token->type != TOKEN_WORD)
|
||||
{
|
||||
perror("Syntax error: expected a word after redirection");
|
||||
// free(redir_op);
|
||||
return NULL;
|
||||
}
|
||||
char *target = strdup(token->data);
|
||||
POP_TOKEN();
|
||||
|
||||
return ast_create_redir(io_number, redir_type, target);
|
||||
*/
|
||||
return ast_create_redir(target, io_number, redir_type);
|
||||
}
|
||||
|
||||
struct ast *parse_prefix(struct lexer_context *ctx)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue