From a290bb0b045534fce5c7d7b8a7acfb4576f23ac8 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 1 Sep 2014 01:00:30 +0900 Subject: [PATCH] [repl] support multiple line input --- contrib/20.repl/repl.scm | 52 +++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/contrib/20.repl/repl.scm b/contrib/20.repl/repl.scm index 4998fbe4..76cadaa0 100644 --- a/contrib/20.repl/repl.scm +++ b/contrib/20.repl/repl.scm @@ -23,30 +23,34 @@ (define-readline) (define (repl) - (let ((line (readline "> "))) - (if (eof-object? line) - (newline) ; exit - (begin - (add-history line) - (call/cc - (lambda (exit) - (with-exception-handler - (lambda (condition) - (display (error-object-message condition) (current-error-port)) - (newline) - (exit)) - (lambda () - ;; FIXME - ;; non-local exception jump from inside call-with-port - ;; fails with segv, though i don't know why... - (let ((port (open-input-string line))) - (let loop ((expr (read port))) - (unless (eof-object? expr) - (write (eval expr '(picrin user))) - (newline) - (loop (read port)))) - (close-port port)))))) - (repl))))) + (let loop ((buf "")) + (let ((line (readline (if (equal? buf "") "> " "* ")))) + (if (eof-object? line) + (newline) ; exit + (let ((str (string-append buf line "\n"))) + (add-history line) + (call/cc + (lambda (exit) + (with-exception-handler + (lambda (condition) + (unless (equal? (error-object-message condition) "unexpected EOF") + (display (error-object-message condition) (current-error-port)) + (newline) + (set! str "")) + (exit)) + (lambda () + ;; FIXME + ;; non-local exception jump from inside call-with-port + ;; fails with segv, though i don't know why... + (let ((port (open-input-string str))) + (let next ((expr (read port))) + (unless (eof-object? expr) + (write (eval expr '(picrin user))) + (newline) + (set! str "") + (next (read port)))) + (close-port port)))))) + (loop str)))))) (export repl))