Add function for reading whole files
* geesh/parser.scm (read-sh-all): New public function for reading all commands from a port. (make-parser): Simplify AST forms when reading multiple commands. * tests/parser.scm: Test it.
This commit is contained in:
parent
3ec520596c
commit
b807b72a7c
|
@ -24,7 +24,8 @@
|
|||
#:use-module (srfi srfi-11)
|
||||
#:use-module (srfi srfi-41)
|
||||
#:use-module (system base lalr)
|
||||
#:export (read-sh))
|
||||
#:export (read-sh
|
||||
read-sh-all))
|
||||
|
||||
;;; Commentary:
|
||||
;;;
|
||||
|
@ -229,9 +230,9 @@ the same number of times.)"
|
|||
|
||||
(program
|
||||
(linebreak complete-commands linebreak)
|
||||
: (if (null? (cdr $2)) (car $2) (reverse! $2))
|
||||
: (reverse! $2)
|
||||
(linebreak)
|
||||
: (eof-object))
|
||||
: '())
|
||||
|
||||
(complete-commands
|
||||
(complete-commands newline-list complete-command)
|
||||
|
@ -786,3 +787,11 @@ port if @var{port} is unspecified)."
|
|||
(lex (lambda () (if stop? '*eoi* (pre-lex))))
|
||||
(parse (make-parser #:command-hook stop!)))
|
||||
(parse lex syntax-error)))
|
||||
|
||||
(define* (read-sh-all #:optional (port #f))
|
||||
"Read all complete Shell commands from @var{port} (or the current
|
||||
input port if @var{port} is unspecified)."
|
||||
(let* ((port (or port (current-input-port)))
|
||||
(lex (make-lexer port read-sh/bracketed read-sh/backquoted))
|
||||
(parse (make-parser)))
|
||||
(parse lex syntax-error)))
|
||||
|
|
|
@ -354,4 +354,11 @@
|
|||
(list (read-sh port)
|
||||
(read-sh port)))))
|
||||
|
||||
(test-equal "Reads all commands"
|
||||
'((<sh-exec> "echo" "foo")
|
||||
(<sh-exec> "echo" "bar"))
|
||||
(call-with-input-string "echo foo
|
||||
echo bar"
|
||||
read-sh-all))
|
||||
|
||||
(test-end)
|
||||
|
|
Loading…
Reference in New Issue