diff options
author | Andy Wingo <wingo@pobox.com> | 2011-03-03 23:19:35 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2011-03-03 23:19:35 +0100 |
commit | 859e58ae8a77c0c725a5027d1bb3809e9772076e (patch) | |
tree | 69ac7be275e8d1e76c39f2364d17436a0b7b413c | |
parent | d900843c72ee1f34d79527deb38787e581592cf5 (diff) | |
download | guile-859e58ae8a77c0c725a5027d1bb3809e9772076e.tar.gz |
repl.scm refactor
* module/system/repl/repl.scm (flush-leading-whitespace): Rename from
next-char.
(meta-reader): Use flush-leading-whitespace.
(run-repl): Use flush-to-newline after the evaluation, which seems to
be the same as what we did before.
-rw-r--r-- | module/system/repl/repl.scm | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/module/system/repl/repl.scm b/module/system/repl/repl.scm index 0d7aca762..4ad7aec84 100644 --- a/module/system/repl/repl.scm +++ b/module/system/repl/repl.scm @@ -43,7 +43,7 @@ (lambda* (#:optional (port (current-input-port))) (with-input-from-port port (lambda () - (let ((ch (next-char #t))) + (let ((ch (flush-leading-whitespace))) (cond ((eof-object? ch) ;; EOF objects are not buffered. It's quite possible ;; to peek an EOF then read something else. It's @@ -157,18 +157,17 @@ (lambda (k . args) (abort args)))) #:trap-handler 'disabled))) - (next-char #f) ;; consume trailing whitespace + (flush-to-newline) ;; consume trailing whitespace (prompt-loop)))) (lambda (k status) status))) -(define (next-char wait) - (if (or wait (char-ready?)) - (let ((ch (peek-char))) - (cond ((eof-object? ch) ch) - ((char-whitespace? ch) (read-char) (next-char wait)) - (else ch))) - #f)) +;; Returns first non-whitespace char. +(define (flush-leading-whitespace) + (let ((ch (peek-char))) + (cond ((eof-object? ch) ch) + ((char-whitespace? ch) (read-char) (flush-leading-whitespace)) + (else ch)))) (define (flush-to-newline) (if (char-ready?) |