Replace geesh script with gash.

* geesh/repl.scm (run-repl): Add optional parse? parameter.
* gash/gash.scm (main): Rewrite to use Geesh parser and evaluator.
* scripts/geesh.in: Remove.
* Makefile.am: Remove scripts/geesh; adjust XFAIL_TESTS.
* .gitignore: Update.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
This commit is contained in:
Jan Nieuwenhuizen 2018-12-17 21:15:12 +01:00 committed by Timothy Sample
parent 171796317f
commit cf5611f6d4
4 changed files with 39 additions and 48 deletions

1
.gitignore vendored
View File

@ -44,7 +44,6 @@ coverage/*
lcov.info lcov.info
pre-inst-env pre-inst-env
scripts/gash scripts/gash
scripts/geesh
tests/*.trs tests/*.trs
tests/spec/oil tests/spec/oil
tests/spec/oil-link tests/spec/oil-link

View File

@ -105,8 +105,7 @@ MODULES = \
geesh/word.scm geesh/word.scm
bin_SCRIPTS = \ bin_SCRIPTS = \
scripts/gash \ scripts/gash
scripts/geesh
do_subst = sed \ do_subst = sed \
-e 's,[@]GUILE[@],$(GUILE),g' \ -e 's,[@]GUILE[@],$(GUILE),g' \
@ -117,10 +116,6 @@ scripts/gash: scripts/gash.in Makefile
$(do_subst) < $(srcdir)/scripts/gash.in > scripts/gash $(do_subst) < $(srcdir)/scripts/gash.in > scripts/gash
chmod a+x scripts/gash chmod a+x scripts/gash
scripts/geesh: scripts/geesh.in Makefile
$(do_subst) < $(srcdir)/scripts/geesh.in > scripts/geesh
chmod a+x scripts/geesh
UNIT_TESTS = \ UNIT_TESTS = \
tests/unit/lexer.scm \ tests/unit/lexer.scm \
tests/unit/parser.scm \ tests/unit/parser.scm \
@ -234,25 +229,16 @@ FULL_TESTS = \
TESTS = $(UNIT_TESTS) $(FULL_TESTS) TESTS = $(UNIT_TESTS) $(FULL_TESTS)
XFAIL_TESTS = \ XFAIL_TESTS = \
tests/00-exit-var.sh \ tests/20-pipe-sed.sh \
tests/03-echo-brace.sh \
tests/07-variable-or-doublequote.sh \
tests/10-if-redirect.sh \
tests/11-for-split-sequence.sh \
tests/11-for-done-subshell.sh \
tests/20-or.sh \
tests/20-exec.sh \
tests/30-substitution-word.sh \
tests/30-substitution-backtick.sh \
tests/30-for-substitution.sh \
tests/30-substitution-assignment-at.sh \
tests/30-substitution-redirect.sh \
tests/40-assignment-eval-echo.sh \
tests/42-sh-export.sh \ tests/42-sh-export.sh \
tests/50-redirect-append.sh \ tests/70-hash.sh \
tests/50-redirect-pipe.sh \ tests/70-hash-hash.sh \
tests/50-redirect-merge.sh \ tests/70-percent.sh \
tests/60-function-at.sh tests/70-percent-percent.sh \
tests/70-percent-space.sh \
tests/70-slash.sh \
tests/70-slash-string.sh \
tests/70-slash-string-slash.sh
# These tests will not be run. Put tests here # These tests will not be run. Put tests here
# that pass or fail based on environmental # that pass or fail based on environmental
@ -264,7 +250,7 @@ BROKEN_TESTS = \
tests/100-cd.sh tests/100-cd.sh
EXTRA_DIST = \ EXTRA_DIST = \
scripts/geesh.in scripts/gash.in
CLEANFILES = \ CLEANFILES = \
$(GOBJECTS) \ $(GOBJECTS) \

View File

@ -21,6 +21,11 @@
#:use-module (gash script) #:use-module (gash script)
#:use-module (gash util) #:use-module (gash util)
#:use-module (geesh environment)
#:use-module (geesh eval)
#:use-module (geesh parser)
#:use-module (geesh repl)
#:export (main #:export (main
%debug-level %debug-level
%prefer-builtins? %prefer-builtins?
@ -57,8 +62,7 @@ Usage: gash [OPTION]... [FILE]...
Options: Options:
-c, --command=STRING Evaluate STRING and exit -c, --command=STRING Evaluate STRING and exit
-e, --errexit Exit upon error -e, --errexit Exit upon error
-d, --debug Enable PEG tracing -d, --debug Verbose debug output
-g, --geesh Use Geesh parser [EXPERIMENTAL]
-h, --help Display this help -h, --help Display this help
-p, --parse Parse the shell script and print the parse tree -p, --parse Parse the shell script and print the parse tree
--prefer-builtins Use builtins, even if command is available in PATH --prefer-builtins Use builtins, even if command is available in PATH
@ -70,7 +74,8 @@ Options:
(display (string-append " (display (string-append "
gash (GASH) " %version " gash (GASH) " %version "
Copyright (C) 2016,2017,2018 R.E.W. van Beusekom <rutger.van.beusekom@gmail.com> Copyright (C) 2016,2017,2018 R.E.W. van Beusekom <rutger.van.beusekom@gmail.com>,
Copyright (C) 2017,2018 Timothy Sample <samplet@ngyro.com>,
and others. and others.
This is Gash, Guile As SHell. Gash is free software and is covered by This is Gash, Guile As SHell. Gash is free software and is covered by
@ -88,12 +93,11 @@ copyleft.
(help (single-char #\h)) (help (single-char #\h))
(parse (single-char #\p)) (parse (single-char #\p))
(prefer-builtins) (prefer-builtins)
(geesh (single-char #\g))
(version (single-char #\v)) (version (single-char #\v))
(xtrace (single-char #\x)))) (xtrace (single-char #\x))))
(args (take-while (negate (cut equal? <> "--")) args)) (args (take-while (negate (cut equal? <> "--")) args))
(options (getopt-long args option-spec #:stop-at-first-non-option #t)) (options (getopt-long args option-spec #:stop-at-first-non-option #t))
(command? (option-ref options 'command #f)) (command (option-ref options 'command #f))
(opt? (lambda (name) (lambda (o) (and (eq? (car o) name) (cdr o))))) (opt? (lambda (name) (lambda (o) (and (eq? (car o) name) (cdr o)))))
(debug (length (filter-map (opt? 'debug) options))) (debug (length (filter-map (opt? 'debug) options)))
(debug? (option-ref options 'debug #f)) (debug? (option-ref options 'debug #f))
@ -102,34 +106,35 @@ copyleft.
(version? (option-ref options 'version #f)) (version? (option-ref options 'version #f))
(files (option-ref options '() '()))) (files (option-ref options '() '())))
(set! %prefer-builtins? (option-ref options 'prefer-builtins #f)) (set! %prefer-builtins? (option-ref options 'prefer-builtins #f))
(set! %geesh-parser? (option-ref options 'geesh #f)) (setopt! 'errexit (option-ref options 'errexit #f))
(set-shell-opt! "errexit" (option-ref options 'errexit #f)) (setopt! 'xtrace (option-ref options 'xtrace #f))
(set-shell-opt! "xtrace" (option-ref options 'xtrace #f))
(when (option-ref options 'debug #f) (when (option-ref options 'debug #f)
(set! %debug-level debug)) (set! %debug-level debug))
(cond (cond
(help? (display-help)) (help? (display-help))
(version? (display-version)) (version? (display-version))
(command? (let ((ast (parse-string command?))) (command (if (null? files)
(if parse? (pretty-print ast) (set-program-arguments (list (car (program-arguments))))
(run ast)) (set-program-arguments files))
(exit (script-status)))) (call-with-input-string command
(lambda (port)
(exit (run-repl port parse?)))))
((pair? files) ((pair? files)
(let* ((script (car files)) (let ((script (car files)))
(ast (file-to-ast script))) (set-program-arguments files)
(if parse? (pretty-print ast) (call-with-input-file script
(parameterize ((%command-line files)) (lambda (port)
(run ast))) (exit (run-repl port))))))
(exit (script-status))))
(#t (let* ((HOME (string-append (getenv "HOME") "/.gash_history")) (#t (let* ((HOME (string-append (getenv "HOME") "/.gash_history"))
(thunk (lambda () (thunk (lambda ()
(let loop ((line (readline (prompt)))) (let loop ((line (readline (prompt))))
(when (not (eof-object? line)) (when (not (eof-object? line))
(let* ((ast (parse-string line))) (let ((ast (call-with-input-string line
(lambda (port) (read-sh port)))))
(when (and ast (when (and ast
(not (string-null? line))) (not (string-null? line)))
(unless parse? (unless parse?
(run ast)) (eval-sh ast))
(add-history line)) (add-history line))
(loop (let ((previous (if ast "" (string-append line "\n"))) (loop (let ((previous (if ast "" (string-append line "\n")))
(next (readline (if ast (prompt) "> ")))) (next (readline (if ast (prompt) "> "))))

View File

@ -30,9 +30,10 @@
;;; ;;;
;;; Code: ;;; Code:
(define* (run-repl #:optional (port (current-input-port))) (define* (run-repl #:optional (port (current-input-port)) parse?)
(let loop ((exp (read-sh port))) (let loop ((exp (read-sh port)))
(match exp (match exp
((? eof-object?) (sh:exit)) ((? eof-object?) (sh:exit))
(_ (eval-sh exp) (_ (if parse? (format #t "~a\n" exp)
(eval-sh exp))
(loop (read-sh port)))))) (loop (read-sh port))))))