feat: toujours les mêmes qui font les pipes. Plus de assert dans ASTs (pour des raisons évidentes de stabilité du code) et nouveaux types (AST_PIPE et AST_NEG), + modifs random dans le parser
This commit is contained in:
parent
07e7d83c60
commit
96626d9850
27 changed files with 238 additions and 86 deletions
|
|
@ -4,6 +4,12 @@
|
|||
#include <sys/types.h>
|
||||
|
||||
#include "lexer_utils.h"
|
||||
|
||||
/*
|
||||
* @brief returns true if token is a redir type, false otherwise
|
||||
*/
|
||||
bool is_token_redir(struct token *token);
|
||||
|
||||
/*
|
||||
* @brief: returns the next (newly allocated) token without consuming it.
|
||||
* if end of input is reached, returns a token of type TOKEN_EOF.
|
||||
|
|
|
|||
|
|
@ -178,6 +178,25 @@ static bool is_end_of_line(char c)
|
|||
return c == EOF || c == '\n';
|
||||
}
|
||||
|
||||
// === 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 is_special_char(char *stream, ssize_t i)
|
||||
{
|
||||
char c = stream[i];
|
||||
|
|
|
|||
|
|
@ -31,16 +31,13 @@ enum lexing_mode
|
|||
|
||||
enum token_type
|
||||
{
|
||||
// Special characters
|
||||
// Blanks
|
||||
TOKEN_NULL = 0,
|
||||
TOKEN_EOF,
|
||||
TOKEN_WORD,
|
||||
TOKEN_NEWLINE,
|
||||
|
||||
// WARNING: quote and double quote should never be used inside a token.
|
||||
TOKEN_QUOTE,
|
||||
TOKEN_DOUBLE_QUOTE,
|
||||
|
||||
// SPecial characters
|
||||
TOKEN_GRAVE,
|
||||
TOKEN_SEMICOLON,
|
||||
TOKEN_COMMENT,
|
||||
|
|
@ -51,8 +48,14 @@ enum token_type
|
|||
TOKEN_RIGHT_PAREN,
|
||||
TOKEN_LEFT_BRACKET,
|
||||
TOKEN_RIGHT_BRACKET,
|
||||
TOKEN_PIPE,
|
||||
TOKEN_NEGATION, // TODO handle
|
||||
|
||||
// redirections
|
||||
// TODO merge into one and use the data field
|
||||
// (Too difficult to handle in the parser because of firsts)
|
||||
// TOKEN_REDIRECTION
|
||||
//
|
||||
// Redirections
|
||||
TOKEN_REDIR_LEFT,
|
||||
TOKEN_REDIR_RIGHT,
|
||||
TOKEN_REDIR_LEFT_RIGHT,
|
||||
|
|
@ -62,7 +65,6 @@ enum token_type
|
|||
TOKEN_REDIR_RIGHT_PIPE,
|
||||
|
||||
TOKEN_IONUMBER,
|
||||
TOKEN_PIPE,
|
||||
|
||||
// Keywords
|
||||
TOKEN_IF,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue