From 210fb08de6c5a9a5b0a7dd7deb737a75d9133b32 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sat, 10 Oct 2020 19:19:41 +0200 Subject: Added comment to parser --- src/parser/expr.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src/parser/expr.c') diff --git a/src/parser/expr.c b/src/parser/expr.c index f4c82ce..8ee7866 100644 --- a/src/parser/expr.c +++ b/src/parser/expr.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/10/10 08:42:24 by cacharle #+# #+# */ -/* Updated: 2020/10/10 09:24:33 by cacharle ### ########.fr */ +/* Updated: 2020/10/10 18:28:02 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,13 @@ ** push last str token */ +/* +** \brief Push tokens which bellong to a redirection in a token list +** \param input Tokens where to extract the redirection tokens +** \param redirs List where to push the redirections tokens +** \return Parsed struct with the unconsumed input +*/ + t_parsed *parse_redir(t_tok_lst *input, t_tok_lst **redirs) { t_parsed *ret; @@ -39,6 +46,13 @@ t_parsed *parse_redir(t_tok_lst *input, t_tok_lst **redirs) return (parsed_new(NULL, input)); } +/* +** \brief Parse a command (this is the continuation of +** parse_cmd splited for norm complience) +** \param input Input tokens +** \return Parsed struct containning a command AST +*/ + static t_parsed *st_parse_cmd_body(t_tok_lst *input) { t_ast *ast; @@ -66,6 +80,14 @@ static t_parsed *st_parse_cmd_body(t_tok_lst *input) return (parsed_new(ast, input)); } +/* +** \brief Check if the first token can be included in a command +** then parse a command +** \param input Input tokens +** \return Parsed error if the first token isn't a redirection or string +** Parsed containning a command AST otherwise +*/ + t_parsed *parse_cmd(t_tok_lst *input) { t_parsed *ret; @@ -80,6 +102,14 @@ t_parsed *parse_cmd(t_tok_lst *input) return (st_parse_cmd_body(input)); } +/* +** \brief Parse a parenthesized expression +** \param input Input tokens +** \return Parsed containning a parenthesis AST +** Parsed error if parenthesis don't match +** \note Parenthesis can be followed by redirections +*/ + static t_parsed *st_parse_parenthesis(t_tok_lst *input) { t_parsed *parsed; @@ -110,8 +140,9 @@ static t_parsed *st_parse_parenthesis(t_tok_lst *input) } /* -** try to parse parenthesis, if fail parse a command. -** parenthesis can be followed by redirections +** \brief Try to parse parenthesis, if fail parse a command. +** \param input Input tokens +** \return Whatever parse_parenthesis or parse_cmd returns */ t_parsed *parse_expr(t_tok_lst *input) -- cgit