MiniDevil
As beautiful as a shell
Parser entry point & sub parser prototypes. More...
#include "structs.h"
Include dependency graph for parser.h:
This graph shows which files directly or indirectly include this file:Parser entry point & sub parser prototypes.
Definition in file parser.h.
Functions | |
| t_ast * | parse (t_token *tokens) |
| Parse a token list into an AST. More... | |
| t_ast * | parse_pipeline (t_token **tokens) |
| Parse a pipeline of commands connected by pipes. More... | |
| t_ast * | parse_command (t_token **tokens) |
| Parse a command with all its redirections. More... | |
| t_ast * | parse_simple_command (t_token **tokens) |
| Parse a simple command from consecutive word tokens. More... | |
| char ** | collect_args (t_token **tokens, int *argc) |
| Collect consecutive word tokens into an arguments array. More... | |
| int | print_syntax_error (t_syntax_error err) |
| Print an error message to STDERR. More... | |
| int | is_redirection (t_token_type type) |
| Check if a token type is a redirection operator. More... | |
| int | validate_syntax (t_token *tokens) |
| Run all validation checks on a token list. More... | |
| int | count_word_tokens (t_token *tokens) |
| Count consecutive word token groups. More... | |
| t_ast * | reverse_redir_chain (t_ast *node) |
| Reverse a redirection chain for left to right execution order. More... | |
| char * | join_connected_delim (t_token **tokens, int *quoted) |
| Join connected tokens in a single string. More... | |
Parse a token list into an AST.
Validates syntax and then delegates to parse_pipeline() which handles the recursive descent
| tokens | Head of the token list |
Definition at line 26 of file parser.c.
References parse_pipeline(), and validate_syntax().
Referenced by process_input(), and process_ui_input().
Here is the call graph for this function:
Here is the caller graph for this function:Parse a pipeline of commands connected by pipes.
Left associative tree: "A | B | C" -> PIPE(PIPE(A, B), C)
| tokens | Pointer to current token pointer |
Definition at line 25 of file parser_pipeline.c.
References create_pipe_node(), free_ast(), t_token::next, parse_command(), TOKEN_PIPE, and t_token::type.
Referenced by parse().
Here is the call graph for this function:
Here is the caller graph for this function:Parse a command with all its redirections.
Parses a simple command and wraps it in redirection nodes as long as redirection tokens follow. After each redirection it collects any trailing word tokens and adds them to the command's args
| tokens | Pointer to current token pointer (advanced) |
Definition at line 134 of file parser_redir.c.
References collect_and_merge_remaining_args(), get_command_node(), is_redirection(), parse_one_redirection(), parse_simple_command(), and reverse_redir_chain().
Referenced by parse_pipeline().
Here is the call graph for this function:
Here is the caller graph for this function:Parse a simple command from consecutive word tokens.
Collects the arguments via collect_args() and wraps them in a NODE_COMMAND AST node
| tokens | Pointer to current token pointer |
Definition at line 117 of file parser_cmd.c.
References collect_args(), and create_cmd_node().
Referenced by parse_command().
Here is the call graph for this function:
Here is the caller graph for this function:| char** collect_args | ( | t_token ** | tokens, |
| int * | argc | ||
| ) |
Collect consecutive word tokens into an arguments array.
| tokens | Pointer to current token pointer |
| argc | Number of arguments collected |
Definition at line 88 of file parser_cmd.c.
References count_word_tokens(), and fill_args_array().
Referenced by collect_and_merge_remaining_args(), and parse_simple_command().
Here is the call graph for this function:
Here is the caller graph for this function:| int print_syntax_error | ( | t_syntax_error | err | ) |
Print an error message to STDERR.
| err | Error code |
Definition at line 44 of file parser_grammar_error.c.
References ERR_NONE, and get_error_msg().
Referenced by validate_empty(), validate_pipe_position(), and validate_redir_syntax().
Here is the call graph for this function:
Here is the caller graph for this function:| int is_redirection | ( | t_token_type | type | ) |
Check if a token type is a redirection operator.
| type | Token type to check |
Definition at line 62 of file parser_grammar_error.c.
References TOKEN_APPEND, TOKEN_HEREDOC, TOKEN_REDIR_IN, and TOKEN_REDIR_OUT.
Referenced by parse_command(), and validate_redir_syntax().
Here is the caller graph for this function:| int validate_syntax | ( | t_token * | tokens | ) |
Run all validation checks on a token list.
| tokens | Token list to validate |
Definition at line 88 of file parser_grammar.c.
References validate_empty(), validate_pipe_position(), and validate_redir_syntax().
Referenced by parse().
Here is the call graph for this function:
Here is the caller graph for this function:| int count_word_tokens | ( | t_token * | tokens | ) |
Count consecutive word token groups.
Connected tokens count as 1 group
| tokens | Token list starting position |
Definition at line 25 of file parser_cmd.c.
References t_token::connected, t_token::next, TOKEN_WORD, and t_token::type.
Referenced by collect_args().
Here is the caller graph for this function:Reverse a redirection chain for left to right execution order.
The parser builds redirections with the outermost being last, so this reverses the chain so that the first parsed redirection is outermost, matching BASH's left to right behavior
| node | Outermost redirection |
Definition at line 39 of file parser_redir_utils.c.
References t_redir_node::cmd, t_ast::data, is_redir(), and t_ast_data::redir.
Referenced by parse_command().
Here is the call graph for this function:
Here is the caller graph for this function:| char* join_connected_delim | ( | t_token ** | tokens, |
| int * | quoted | ||
| ) |
Join connected tokens in a single string.
| tokens | Pointer to current token pointer |
| quoted | Set to 1 if any was quoted |
Definition at line 69 of file parser_redir_utils.c.
References t_token::next, and QUOTE_NONE.
Referenced by parse_one_redirection().
Here is the caller graph for this function: