flush all input on a read error
authorAndy Wingo <wingo@pobox.com>
Sun, 27 Feb 2011 22:26:08 +0000 (23:26 +0100)
committerAndy Wingo <wingo@pobox.com>
Sun, 27 Feb 2011 22:26:08 +0000 (23:26 +0100)
* module/system/repl/repl.scm (flush-all-input): New helper.
  (prompting-meta-read): Flush all input on a read error, as we could be
  within some expression or a string or something.

module/system/repl/repl.scm

index 6eb29be..0d7aca7 100644 (file)
                  meta-command-token)
                 (else (read port env))))))))
         
+(define (flush-all-input)
+  (if (and (char-ready?)
+           (not (eof-object? (peek-char))))
+      (begin
+        (read-char)
+        (flush-all-input))))
+
 ;; repl-reader is a function defined in boot-9.scm, and is replaced by
 ;; something else if readline has been activated. much of this hoopla is
 ;; to be able to re-use the existing readline machinery.
@@ -72,6 +79,7 @@
         (else
          (format (current-output-port) "While reading expression:\n")
          (print-exception (current-output-port) #f key args)
+         (flush-all-input)
          *unspecified*)))))
 
 \f