|
myshell 2.0.0
|
Tokens processing utilities. More...
Functions | |
| void | postprocess_tokens (tokens_t &tokens) |
| Perform postprocessing on a vector of tokens. | |
| void | insert_tokens (tokens_t &tokens, tokens_t::iterator &pos, const tokens_t &sub_tokens) |
| Insert a sequence of tokens into a vector of tokens on a given position. | |
| tokens_t | split_words (const std::string_view input) |
| Perform word splitting on the given input string, breaking it down into a vector of WORD tokens. | |
| void | set_variables (tokens_t &tokens) |
| Sets internal variables based on VAR_DECL tokens in a vector of tokens. | |
| void | expand_aliases (tokens_t &tokens) |
| Expand command aliases within a vector of tokens. | |
| void | expand_vars (tokens_t &tokens) |
| Expand variables within a vector of tokens. | |
| void | substitute_commands (tokens_t &tokens) |
| Perform command substitution within a vector of tokens. | |
| void | expand_glob (tokens_t &tokens) |
| Expand glob patterns within a vector of tokens. | |
| void | squash_tokens (tokens_t &tokens) |
| Squash the adjacent tokens flagged as WORD_LIKE. | |
| void | check_syntax (const tokens_t &tokens) |
| Check the syntax of a vector of tokens. | |
| simple_command_ptr | make_simple_command (const tokens_t &tokens) |
| Construct a shared pointer to a simple command from a vector of tokens. | |
| command | split_commands (tokens_t &tokens) |
| Split a vector of tokens into a tree structure of commands. | |
| void | process_tokens (tokens_t &tokens) |
| Process a vector of tokens. | |
Tokens processing utilities.
| void check_syntax | ( | const tokens_t & | tokens | ) |
Check the syntax of a vector of tokens.
If syntax is incorrect, throws an exception.
| tokens | A vector of tokens to check. |
| msh_exception | if syntax is incorrect. |
| void expand_aliases | ( | tokens_t & | tokens | ) |
Expand command aliases within a vector of tokens.
Takes a vector of tokens and expands command aliases by replacing alias, defined with malias, with their corresponding token sequences. Uses a stack-based approach to perform alias expansion, ensuring that nested aliases are also expanded. Only COMMAND tokens are eligible for alias expansion.
| tokens | A vector of tokens to expand aliases within. |
| void expand_glob | ( | tokens_t & | tokens | ) |
Expand glob patterns within a vector of tokens.
Iterates through a vector of tokens and expands glob patterns within tokens by matching them against files in the file system. If no files are matched, the glob pattern is left unchanged. Token with matched glob pattern is replaced with a sequence of WORD tokens containing the matched file names.
Tokens flagged as GLOB_NO_EXPAND are not expanded.
| tokens | A vector of tokens to process and expand glob patterns within. |
| void expand_vars | ( | tokens_t & | tokens | ) |
Expand variables within a vector of tokens.
Iterates through a vector of tokens and expands variables within tokens by replacing them with their corresponding values. The expansion priority is given to internal variables. If no variable with the given name is found, expansion result to an empty string.
Tokens flagged as VAR_NO_EXPAND are not expanded. The word splitting is performed on the resulting string, unless the token is flagged as NO_WORD_SPLIT.
| tokens | A vector of tokens to process and expand variables within. |
| void insert_tokens | ( | tokens_t & | tokens, |
| tokens_t::iterator & | pos, | ||
| const tokens_t & | sub_tokens ) |
Insert a sequence of tokens into a vector of tokens on a given position.
| tokens | A vector of tokens to insert into. |
| pos | An iterator pointing to the position to insert tokens at. |
| sub_tokens | A vector of tokens to insert. |
| simple_command_ptr make_simple_command | ( | const tokens_t & | tokens | ) |
Construct a shared pointer to a simple command from a vector of tokens.
| tokens | A vector of tokens to construct a simple command from. |
| void postprocess_tokens | ( | tokens_t & | tokens | ) |
Perform postprocessing on a vector of tokens.
Postprocessing can include some specific operations that must be performed after tokenization, but before any other processing steps. For example, variable declarations that appear as malias or mexport commands are not eligible for word splitting and filename expansion.
| tokens | A vector of tokens to postprocess. |
| void process_tokens | ( | tokens_t & | tokens | ) |
Process a vector of tokens.
Performs all necessary token processing steps in the correct order.
| tokens | A vector of tokens to process. |
| msh_exception | if an error occurs during token processing. Must be handled elsewhere. |
| void set_variables | ( | tokens_t & | tokens | ) |
Sets internal variables based on VAR_DECL tokens in a vector of tokens.
Iterates through a vector of tokens, identifies VAR_DECL tokens, and sets corresponding variables based on their values. If a VAR_DECL token is followed by a token flagged as WORD_LIKE without separators, the two tokens are combined and the resulting string is assigned to the variable.
| tokens | A vector of tokens to process and update variable values. |
| command split_commands | ( | tokens_t & | tokens | ) |
Split a vector of tokens into a tree structure of commands.
Each node of the tree is a command object, which can be either a simple command or a connection command. The connection command contains a connector token and two command objects, lhs and rhs. Returns the root of the tree.
| tokens | A vector of tokens to split. |
| tokens_t split_words | ( | const std::string_view | input | ) |
Perform word splitting on the given input string, breaking it down into a vector of WORD tokens.
| input | The input string to be split. |
| void squash_tokens | ( | tokens_t & | tokens | ) |
Squash the adjacent tokens flagged as WORD_LIKE.
| tokens | A vector of tokens to process. |
| void substitute_commands | ( | tokens_t & | tokens | ) |
Perform command substitution within a vector of tokens.
Iterates through a vector of tokens and replaces tokens of type COM_SUB with the output of the underlying command by executing it in a subshell.
Any trailing newlines are removed from the output. The word splitting is performed on the resulting string, unless the token is flagged as NO_WORD_SPLIT.
| tokens | A vector of tokens to process and substitute command substitutions within. |
| msh_exception | if an error occurs during command execution. |