From 941099778b59da6b904c284e8a82affe4766124b Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 30 Mar 2020 22:27:16 +0200 Subject: Added doc --- include/ms_parse.h | 83 +++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 44 deletions(-) (limited to 'include/ms_parse.h') diff --git a/include/ms_parse.h b/include/ms_parse.h index 74604e5..0810ec2 100644 --- a/include/ms_parse.h +++ b/include/ms_parse.h @@ -15,67 +15,49 @@ # include "minishell.h" -/* -** Context free grammar: +/** +** \file ms_parse.h +** \brief Input parsing and AST manipulation ** +** Context free grammar: +** ``` ** redir_in ::= '<' ** redir_out ::= '>' ** redir_append ::= '>>' ** string ::= '\'' .+ '\'' | '"' .+ '"' | [^ ]+ ** sep ::= '&&' | '||' | '|' | ';' ** expr ::= | | | -** sexpr ::= + -** line ::= | +** cmd ::= + +** line ::= | +** ``` */ -/* -** TAG_CMD: command name -** TAG_ARG: command argument -** TAG_ENDCMD: `;` -** TAG_PIPE: `|` -** TAG_AND: `&&` -** TAG_OR: `||` -** TAG_REDIR_OUT: `>` -** TAG_REDIR_IN: `<` -** TAG_REDIR_APPEND: `>>` +/** +** \brief AST node tag +** \param TAG_STRING string +** \param TAG_SEP `;` | `|` | `&&` | `||` +** \param TAG_REDIR_OUT `>` +** \param TAG_REDIR_IN `<` +** \param TAG_REDIR_APPEND `>>` */ typedef enum { - TAG_CMD, - TAG_ARG, - TAG_ENDCMD, - TAG_PIPE, - TAG_AND, - TAG_OR, + TAG_STRING, + TAG_SEP, TAG_REDIR_OUT, TAG_REDIR_IN, - TAG_REDIR_APPEND + TAG_REDIR_APPEND, + TAG_CMD, + TAG_LINE, } t_tag; -/* -** AST (Abstract Syntax Tree) -** A node of the ast is represented by a tag (his type) and a content associated with it. -** (i.e a TAG_CMD would be paired with the command executable name) -** Each node also has children node which must be evaluated before him -** -** examle: "echo foo bar && ls" -** -** tags: -** TAG_AND -** / \ -** / \ -** TAG_CMD TAG_CMD -** / \ -** TAG_ARG TAG_ARG -** -** content: -** && -** / \ -** / \ -** echo ls -** / \ -** foo bar +/** +** \brief AST (Abstract Syntax Tree) +** \param tag tag (type) of node +** \param content substring of the parsed string which corespond to tag +** \param children_num number of children +** \param children children nodes */ typedef struct s_ast @@ -86,6 +68,11 @@ typedef struct s_ast struct s_ast** children; } t_ast; + +/* +** lexer.c +*/ + char **ms_lexer(char *input); /* @@ -94,4 +81,12 @@ char **ms_lexer(char *input); t_ast *ms_parse(char *input); +/* +** ast.c +*/ + +t_ast *ms_ast_new(t_tag tag); +void ms_ast_destroy(t_ast *ast); +void ms_ast_iter(t_ast *ast, void (*f)(void *f_arg, t_ast *children), void *arg); + #endif -- cgit