diff options
Diffstat (limited to '42sh/src/helper.c')
| -rw-r--r-- | 42sh/src/helper.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/42sh/src/helper.c b/42sh/src/helper.c new file mode 100644 index 0000000..7f936fc --- /dev/null +++ b/42sh/src/helper.c @@ -0,0 +1,43 @@ +#include "helper.h" + +int _process_input(struct string *input) +{ + struct lexer *lexer = lexer_new(input); + if (!lexer) + { + errx(BAD_GRAMMAR, "main: unable to create lexer."); + } + + enum parser_state status = OK; + + struct ast *ast = NULL; + int r = SHELL_TRUE; + do + { + ast_free(ast); + ast = parse(lexer, &status); + + if (status == ERROR) + { + errx(BAD_GRAMMAR, "main: parse failed."); + } + + if (env_get("PRETTY_PRINT") != NULL) + { + pretty_print(ast); + } + if (ast) + { + r = eval_ast(ast); + } + } while (ast != NULL && status != ERROR); + if (status == ERROR) + { + ast_free(ast); + } + + string_free(lexer->input); + lexer_free(lexer); + + return r; +} |
