diff options
author | Timothy Sample <samplet@ngyro.com> | 2021-06-23 14:27:40 -0400 |
---|---|---|
committer | Timothy Sample <samplet@ngyro.com> | 2021-06-23 14:27:40 -0400 |
commit | eae0953f31da7bb1355017ed70d32b6773114231 (patch) | |
tree | be1a2808dd233effdaa755c634082c2a57d42432 | |
parent | 57d21182e218bc7ab3a7feff3ad79cc2390dbe67 (diff) |
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).
-rw-r--r-- | gash/parser.scm | 13 |
1 files 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))) |