ifthen WIP

This commit is contained in:
Rutger van Beusekom 2016-10-05 15:50:50 +02:00
parent c201b080d0
commit a5c35947a9
3 changed files with 8 additions and 3 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/guile-2.2 \
-e main -s
--debug -e main -s
!#
;; workaround:
;; -e (@ (sh anguish) main) -s

View File

@ -97,6 +97,9 @@ copyleft.
(define (transform ast)
(match ast
(('script command 'separator) (transform command))
(('if-clause "if" (expression "then" consequent "fi")) `(if ,(transform expression) ,(transform consequent)))
(('if-clause "if" expression "then" consequent "else" alternative "fi") `(if ,(transform expression) ,(transform consequent) ,(transform alternative)))
(('compound-list command ('separator 'break)) (transform command))
(('pipeline command) (transform command))
(('pipeline command piped-commands) (cons 'pipeline (cons (transform command) (transform piped-commands))))
(('simple-command ('word s)) (list (transform s)))
@ -121,7 +124,9 @@ copyleft.
((builtin cmd))
(if (and (pair? cmd) (eq? 'pipeline (car cmd)))
(sh:pipeline (cdr cmd))
(apply system* cmd)))))
(if (eq? 'if (car cmd))
(pretty-print cmd)
(apply system* cmd))))))
(define (prompt)
(let* ((esc (string #\033))

View File

@ -1 +1 @@
if ls * | grep foo; then echo ok; fi
if test -e TODO; then echo exists; fi