From eae0953f31da7bb1355017ed70d32b6773114231 Mon Sep 17 00:00:00 2001 From: Timothy Sample Date: Wed, 23 Jun 2021 14:27:40 -0400 Subject: [PATCH] parser: Simplify default port handling. * gash/parser.scm (read-sh, read-sh-all): Set the default value for the 'port' argument in the usual way (rather than doing it manually). --- gash/parser.scm | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/gash/parser.scm b/gash/parser.scm index 1547bcb..6780c08 100644 --- a/gash/parser.scm +++ b/gash/parser.scm @@ -817,18 +817,15 @@ as escapable." (->command-list (parse port))) #:quoted? quoted?)) -(define* (read-sh #:optional (port #f)) +(define* (read-sh #:optional (port (current-input-port))) "Read a complete Shell command from @var{port} (or the current input port if @var{port} is unspecified)." - (define stop? #f) (define (stop!) (set! stop? #t)) + (parse port #:lex-hook (lambda (lex) (if stop? '*eoi* (lex))) + #:command-hook stop!)) - (let* ((port (or port (current-input-port)))) - (parse port #:lex-hook (lambda (lex) (if stop? '*eoi* (lex))) - #:command-hook stop!))) - -(define* (read-sh-all #:optional (port #f)) +(define* (read-sh-all #:optional (port (current-input-port))) "Read all complete Shell commands from @var{port} (or the current input port if @var{port} is unspecified)." - (->command-list (parse (or port (current-input-port))))) + (->command-list (parse port)))