Core functionality of the lexer.
More...
|
struct | s_lexer_state |
| Structure used by lexer to efficiently have access to a bunch of variables. More...
|
|
Core functionality of the lexer.
Functions to make a correct use of lexing and tokenisation.
◆ MAX_TOKENS_LEX
#define MAX_TOKENS_LEX 1024 |
◆ ft_substr_end_gb()
char * ft_substr_end_gb |
( |
t_garbage * | garbage, |
|
|
char const * | src, |
|
|
unsigned int | start, |
|
|
size_t | end ) |
Allocate memory for a string and copy the content from src.
- Parameters
-
garbage | garbage structure |
src | source string |
start | start index to copy from |
end | end index to copy to |
- Returns
- char* pointer to the new string
◆ init_lexer_state()
Initialize the lexer structure.
Fill the structure with zeros and init the line to search in and allocates the array to the garbage
- Parameters
-
garbage | garbage structure |
lex_st | pointer to the lexer structure |
line | line to verify |
◆ is_operator_char()
int is_operator_char |
( |
char | c | ) |
|
Is |, < or >
- Parameters
-
- Returns
- int 1 if c is operator, 0 otherwise
◆ lexer()
char ** lexer |
( |
t_garbage * | garbage, |
|
|
const char * | line ) |
Create tokens (small chunks) a line with the quotes and operators.
Handle spaces, quotes (' and ') and shell operator (|, <, <<, >, >>). Return an array of tokens (strings), NULL terminated.
- Parameters
-
garbage | garbage structure |
line | line to tokenise |
- Returns
- Array of strings
◆ tokeniser()
Creates a t_command structure that contains all the tokens Fills the command with the environment.
- Parameters
-
data | data structure |
tokens | tokens |
- Returns
- t_command* pointer if OK, NULL if it fails