Author | Jamozed <[email protected]> |
Date | 2021-11-19 03:47:15 |
Commit | 680103862717022549f8b3f49715229b1a1e4b73 |
Parent | 2dbb34a3c85acb630016eb6735147ecf23879630 |
Reimplement compound commands with looped parsing
Diffstat
M | src/eval.c | | | 15 | +++++++-------- |
M | src/lex.c | | | 3 | ++- |
M | src/main.c | | | 3 | --- |
3 files changed, 9 insertions, 12 deletions
diff --git a/src/eval.c b/src/eval.c index 28acf83..f72bb12 100644 --- a/src/eval.c +++ b/src/eval.c @@ -43,15 +43,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. /* Evaluate a string. */ extern void eval(char *src, UINT len) { lex l = lex_init(src, len); - if (Lflag) { lex_debug(&l); goto ret; } + if (Lflag) { lex_debug(&l); return; } - ast a = parse(&l); if (!a) { goto ret; } - if (Pflag) { ast_debug(a); goto ret; } - - _ret = execute(a, fileno(stdin), NULL); - -ret:; - ast_free(a); + for (ast a; l.t.k != TK_EOF; ast_free(a)) { + a = parse(&l); if (!a) { return; } + if (Pflag) { ast_debug(a); continue; } + + _ret = execute(a, fileno(stdin), NULL); + } } /* Evaluate a file. */ diff --git a/src/lex.c b/src/lex.c index e05d4e1..8cc07c1 100644 --- a/src/lex.c +++ b/src/lex.c @@ -91,7 +91,8 @@ skip:; /* Handle single quotes */ else if (C == '\'') for (P += 1;; P += 1) { - if (P == Q) { warn("Missing closing \'"); break; } + /* FIXME memory leak upon missing closing ', needs refinement */ + if (P == Q) { warn("Missing closing \'"); return t; } else if (C == '\'') { break; } else { STACK_PUSH(&s, C); } } diff --git a/src/main.c b/src/main.c index a081388..cdcca1a 100644 --- a/src/main.c +++ b/src/main.c @@ -35,9 +35,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. command, or running an empty command, which results in blank history entries. TODO investigate builtins and their functionality with regards to pipes. - TODO reimplement compound commands without a dedicated AST kind. - FIXME without compound commands of some kind, files cannot be executed, as - they are read in as a single string. */ #include "conf.h"