diff options
author | Andy Wingo <wingo@pobox.com> | 2011-03-03 23:51:20 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2011-03-03 23:51:20 +0100 |
commit | 65fa60ca7a7bbfd712371f7b2471efe7b056839c (patch) | |
tree | 614364ffd4bc3720fec4128485404b7a10dfa05a /module/system/repl/repl.scm | |
parent | 859e58ae8a77c0c725a5027d1bb3809e9772076e (diff) | |
download | guile-65fa60ca7a7bbfd712371f7b2471efe7b056839c.tar.gz |
repl.scm understands comments
* module/system/repl/repl.scm (read-comment, read-scheme-line-comment)
(read-scheme-datum-comment): New helpers.
(meta-reader): Take a language instead of a reader. If we have a
nonwhitespace char, first check to see that it's a comment, and if so,
read it off and loop.
(prompting-meta-read): Call meta-reader with the lang.
Diffstat (limited to 'module/system/repl/repl.scm')
-rw-r--r-- | module/system/repl/repl.scm | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/module/system/repl/repl.scm b/module/system/repl/repl.scm index 4ad7aec84..39f2319bf 100644 --- a/module/system/repl/repl.scm +++ b/module/system/repl/repl.scm @@ -32,6 +32,48 @@ #:export (start-repl run-repl)) +;;; +;;; Comments +;;; +;;; (You don't want a comment to force a continuation line.) +;;; + +(define (read-scheme-line-comment port) + (let lp () + (let ((ch (read-char port))) + (or (eof-object? ch) + (eqv? ch #\newline) + (lp))))) + +(define (read-scheme-datum-comment port) + (read port)) + +;; ch is a peeked char +(define (read-comment lang port ch) + (and (eq? (language-name lang) 'scheme) + (case ch + ((#\;) + (read-char port) + (read-scheme-line-comment port) + #t) + ((#\#) + (read-char port) + (case (peek-char port) + ((#\;) + (read-char port) + (read-scheme-datum-comment port) + #t) + ;; Not doing R6RS block comments because of the possibility + ;; of read-hash extensions. Lame excuse. Not doing scsh + ;; block comments either, because I don't feel like handling + ;; #!r6rs. + (else + (unread-char #\# port) + #f))) + (else + #f)))) + + ;;; ;;; Meta commands @@ -39,7 +81,7 @@ (define meta-command-token (cons 'meta 'command)) -(define (meta-reader read env) +(define (meta-reader lang env) (lambda* (#:optional (port (current-input-port))) (with-input-from-port port (lambda () @@ -52,7 +94,9 @@ ((eqv? ch #\,) (read-char port) meta-command-token) - (else (read port env)))))))) + ((read-comment lang port ch) + *unspecified*) + (else ((language-reader lang) port env)))))))) (define (flush-all-input) (if (and (char-ready?) @@ -70,8 +114,7 @@ (catch #t (lambda () (repl-reader (lambda () (repl-prompt repl)) - (meta-reader (language-reader (repl-language repl)) - (current-module)))) + (meta-reader (repl-language repl) (current-module)))) (lambda (key . args) (case key ((quit) @@ -116,7 +159,7 @@ (let prompt-loop () (let ((exp (prompting-meta-read repl))) (cond - ((eqv? exp *unspecified*)) ; read error, pass + ((eqv? exp *unspecified*)) ; read error or comment, pass ((eq? exp meta-command-token) (catch #t (lambda () |