MiniDevil
As beautiful as a shell
Lexer, tokenizer, expander, and quote handling prototypes. More...
#include "structs.h"
Include dependency graph for token.h:
This graph shows which files directly or indirectly include this file:Lexer, tokenizer, expander, and quote handling prototypes.
Definition in file token.h.
Functions | |
| t_token * | create_token (t_token_type type, char *value) |
| Allocate and initialize a new token. More... | |
| void | free_token (t_token *token) |
| Free a single token and its value str. More... | |
| void | free_token_list (t_token *head) |
| Free the entire token linked list. More... | |
| void | add_token (t_token **head, t_token *new_token) |
| Add a token to the end of a linked list. More... | |
| int | is_operator (char c) |
| Check if a character is a shell operator. More... | |
| int | is_whitespace (char c) |
| Check if a character is whitespace. More... | |
| int | is_word_end (char c) |
| Check if a character ends a word token. More... | |
| t_token_type | get_operator_token_type (char *str, int *len) |
| Determine operator token type and its length in characters. More... | |
| int | process_word_token (char *s, t_token **head) |
| Process a word token composed of quoted and unquoted chunks. More... | |
| int | process_operator_token (char *input, t_token **head) |
| Process an operator token. More... | |
| t_token * | tokenize (char *input) |
| Tokenize the input string into a linked list of tokens. More... | |
| int | is_dollar_quote (t_token *tok) |
Check if a token is a $ connected to a quoted token. More... | |
| int | is_var_char (char c) |
| Check if a character is valid in a variable name. More... | |
| char * | extract_var_name (char *str, int *len) |
Extract a variable name from after the $ More... | |
| char * | append_char (char *str, char c) |
| Append a single character to an allocated string. More... | |
| char * | append_str (char *s1, char *s2) |
| Concatenates 2 strings and frees the first. More... | |
| char * | expand_variables (char *str, t_env *env_list, t_quote_type quote_type, int exit_status) |
| Expand all $VARIABLE in a string. More... | |
| int | expand_all_tokens (t_token *tokens, t_shell *shell) |
| Expand all token values before parsing. More... | |
| char * | expand_full (char *str, t_env *env, t_quote_type qt, int exit_status) |
| Handles variable expansion and tilde expansion. More... | |
| t_token* create_token | ( | t_token_type | type, |
| char * | value | ||
| ) |
Allocate and initialize a new token.
The new token starts with quote_type = QUOTE_NONE, connected = 0 and next = NULL
| type | Token type |
| value | Text content |
Definition at line 26 of file token.c.
References t_token::connected, t_token::next, QUOTE_NONE, t_token::quote_type, t_token::type, and t_token::value.
Referenced by process_operator_token(), and process_word_token().
Here is the caller graph for this function:| void free_token | ( | t_token * | token | ) |
Free a single token and its value str.
| token | Token to free |
Definition at line 51 of file token.c.
References t_token::value.
Referenced by free_token_list().
Here is the caller graph for this function:| void free_token_list | ( | t_token * | head | ) |
Free the entire token linked list.
| head | Head of list to free |
Definition at line 64 of file token.c.
References free_token(), and t_token::next.
Referenced by process_input(), process_ui_input(), and tokenize().
Here is the call graph for this function:
Here is the caller graph for this function:Add a token to the end of a linked list.
| head | Pointer to head pointer |
| new_token | Token to add |
Definition at line 84 of file token.c.
References t_token::next.
Referenced by process_operator_token(), and process_word_token().
Here is the caller graph for this function:| int is_operator | ( | char | c | ) |
Check if a character is a shell operator.
| c | Character to test |
Definition at line 21 of file tokenizer_utils.c.
Referenced by extract_unquoted(), is_word_end(), process_word_token(), and tokenize().
Here is the caller graph for this function:| int is_whitespace | ( | char | c | ) |
Check if a character is whitespace.
| c | Character to test |
Definition at line 32 of file tokenizer_utils.c.
Referenced by extract_unquoted(), is_word_end(), process_word_token(), and tokenize().
Here is the caller graph for this function:| int is_word_end | ( | char | c | ) |
Check if a character ends a word token.
| c | Character to test |
Definition at line 43 of file tokenizer_utils.c.
References is_operator(), and is_whitespace().
Here is the call graph for this function:| t_token_type get_operator_token_type | ( | char * | str, |
| int * | len | ||
| ) |
Determine operator token type and its length in characters.
| str | Input at the operator position |
| len | Operator length (1 or 2) |
Definition at line 63 of file tokenizer_utils.c.
References TOKEN_APPEND, TOKEN_HEREDOC, TOKEN_PIPE, TOKEN_REDIR_IN, TOKEN_REDIR_OUT, and TOKEN_WORD.
Referenced by process_operator_token().
Here is the caller graph for this function:| int process_word_token | ( | char * | s, |
| t_token ** | head | ||
| ) |
Process a word token composed of quoted and unquoted chunks.
Parses adjacent chunks (for example hello"world"'!' -> 3 connected tokens)
| s | Input string at word position |
| head | Pointer to token lsit head |
Definition at line 80 of file tokenizer.c.
References add_token(), t_token::connected, create_token(), extract_quoted(), extract_unquoted(), is_operator(), is_whitespace(), t_token::quote_type, and TOKEN_WORD.
Referenced by tokenize().
Here is the call graph for this function:
Here is the caller graph for this function:| int process_operator_token | ( | char * | input, |
| t_token ** | head | ||
| ) |
Process an operator token.
Determines the operator type and length, creates a token and appends it
| input | Input at the operator character |
| head | Pointer to token list head |
Definition at line 118 of file tokenizer.c.
References add_token(), create_token(), and get_operator_token_type().
Referenced by tokenize().
Here is the call graph for this function:
Here is the caller graph for this function:| t_token* tokenize | ( | char * | input | ) |
Tokenize the input string into a linked list of tokens.
The tokenizer entry point: skips whitespaces and dispatches each segment to process_operator_token() or process_word_token()
| input | Raw input string |
Definition at line 144 of file tokenizer.c.
References free_token_list(), is_operator(), is_whitespace(), process_operator_token(), and process_word_token().
Referenced by process_input(), and process_ui_input().
Here is the call graph for this function:
Here is the caller graph for this function:| int is_dollar_quote | ( | t_token * | token | ) |
Check if a token is a $ connected to a quoted token.
Detects the pattern: $"TOKEN_WORD" or $'TOKEN_WORD' + connected + next has quotes
| token | Token to inspect |
Definition at line 25 of file expander_utils.c.
References t_token::connected, t_token::next, QUOTE_NONE, and t_token::value.
Referenced by expand_all_tokens().
Here is the caller graph for this function:| int is_var_char | ( | char | c | ) |
Check if a character is valid in a variable name.
| c | Character to check |
_ and 0 otherwise Definition at line 40 of file expander_utils.c.
Referenced by extract_var_name(), and handle_dollar_sign().
Here is the caller graph for this function:| char* extract_var_name | ( | char * | str, |
| int * | len | ||
| ) |
Extract a variable name from after the $
If the first char is a digit, it returns the only digit (matching BASH). Otherwise it scans for valid variable characters (alphanumeric and _)
| str | String starting after $ |
| len | Number of characters consumed |
Definition at line 55 of file expander_utils.c.
References is_var_char().
Referenced by process_dollar().
Here is the call graph for this function:
Here is the caller graph for this function:| char* append_char | ( | char * | str, |
| char | c | ||
| ) |
Append a single character to an allocated string.
| str | Original string |
| c | Character to append |
Definition at line 79 of file expander_utils.c.
Referenced by expand_variables(), handle_dollar_sign(), and process_dollar().
Here is the caller graph for this function:| char* append_str | ( | char * | s1, |
| char * | s2 | ||
| ) |
Concatenates 2 strings and frees the first.
If s2 is NULL it returns s1 unchanged
| s1 | First string |
| s2 | Second string |
Definition at line 113 of file expander_utils.c.
Referenced by get_append_value(), handle_special_var(), and process_dollar().
Here is the caller graph for this function:| char* expand_variables | ( | char * | str, |
| t_env * | env_list, | ||
| t_quote_type | quote_type, | ||
| int | exit_status | ||
| ) |
Expand all $VARIABLE in a string.
| str | Input string |
| env_list | Environment list for the variables lookups |
| quote_type | Quote context (QUOTE_SINGLE = no expansion) |
| exit_status | Last exit status for $? expansion |
Definition at line 111 of file expander.c.
References append_char(), handle_dollar_sign(), and QUOTE_SINGLE.
Referenced by expand_full(), and write_heredoc_line().
Here is the call graph for this function:
Here is the caller graph for this function:Expand all token values before parsing.
<<) are not exp$ connected to a quoted token is replaced with an empty string| tokens | Token list head |
| shell | Shell state |
Definition at line 150 of file expander.c.
References t_shell::env, t_shell::exit_status, expand_full(), is_dollar_quote(), t_token::next, QUOTE_SINGLE, t_token::quote_type, TOKEN_HEREDOC, TOKEN_WORD, t_token::type, and t_token::value.
Referenced by process_input(), and process_ui_input().
Here is the call graph for this function:
Here is the caller graph for this function:| char* expand_full | ( | char * | str, |
| t_env * | env, | ||
| t_quote_type | qt, | ||
| int | exit_status | ||
| ) |
Handles variable expansion and tilde expansion.
Tilde expansions run first to conform with BASH and correctly handling:
export TEST="~"echo $TEST| str | Input string |
| env | Environment list |
| qt | Quote type |
| exit_status | Exit status for $? |
Definition at line 60 of file tilde_expand.c.
References expand_tilde(), and expand_variables().
Referenced by expand_all_tokens().
Here is the call graph for this function:
Here is the caller graph for this function: