aboutsummaryrefslogtreecommitdiff
path: root/src/parser/expr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/expr.c')
-rw-r--r--src/parser/expr.c37
1 files changed, 34 insertions, 3 deletions
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 <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)