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
pre-inst-env
scripts/gash
scripts/geesh
tests/*.trs
tests/spec/oil
tests/spec/oil-link

View File

@ -105,8 +105,7 @@ MODULES = \
geesh/word.scm
bin_SCRIPTS = \
scripts/gash \
scripts/geesh
scripts/gash
do_subst = sed \
-e 's,[@]GUILE[@],$(GUILE),g' \
@ -117,10 +116,6 @@ scripts/gash: scripts/gash.in Makefile
$(do_subst) < $(srcdir)/scripts/gash.in > 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 = \
tests/unit/lexer.scm \
tests/unit/parser.scm \
@ -234,25 +229,16 @@ FULL_TESTS = \
TESTS = $(UNIT_TESTS) $(FULL_TESTS)
XFAIL_TESTS = \
tests/00-exit-var.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/20-pipe-sed.sh \
tests/42-sh-export.sh \
tests/50-redirect-append.sh \
tests/50-redirect-pipe.sh \
tests/50-redirect-merge.sh \
tests/60-function-at.sh
tests/70-hash.sh \
tests/70-hash-hash.sh \
tests/70-percent.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
# that pass or fail based on environmental
@ -264,7 +250,7 @@ BROKEN_TESTS = \
tests/100-cd.sh
EXTRA_DIST = \
scripts/geesh.in
scripts/gash.in
CLEANFILES = \
$(GOBJECTS) \

View File

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

View File

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