From: Noah Lavine <noah.b.lavine@gmail.com>
To: Andy Wingo <wingo@pobox.com>
Cc: "Jose A. Ortega Ruiz" <jao@gnu.org>, guile-devel@gnu.org
Subject: Re: problem with trailing comment in repl
Date: Sun, 13 Feb 2011 16:27:16 -0500 [thread overview]
Message-ID: <AANLkTi=DFDr2nO1WeuxLkWmSO+TO6A=2gwbkOCrOq4E+@mail.gmail.com> (raw)
In-Reply-To: <m3d3mv91yd.fsf@unquote.localdomain>
[-- Attachment #1: Type: text/plain, Size: 957 bytes --]
The attached patch does it. I almost hate to commit it because it's
such a hack, but this is from my last Guile session:
scheme@(guile-user)> 'foo
$2 = foo
scheme@(guile-user)> 'foo ; hi there!
$3 = foo
scheme@(guile-user)> ; why, hello!
scheme@(guile-user)> ,q
Noah
On Sun, Feb 13, 2011 at 2:19 PM, Andy Wingo <wingo@pobox.com> wrote:
> Hi Noah,
>
> I think it makes sense to have a reader that actually returns comments.
> That, to me, is the general solution: the REPL reader just treats a
> comment as whitespace.
>
> On Sun 13 Feb 2011 16:22, Noah Lavine <noah.b.lavine@gmail.com> writes:
>
>> - The quicker way: if the language in use is scheme, change the
>> next-char function (repl.scm line 205) to know about comments, so that
>> if it saw a semicolon, it would snarf everything until the end of the
>> line.
>
> Nasty, but a good idea I think! Care to submit a patch? :)
>
> Andy
> --
> http://wingolog.org/
>
[-- Attachment #2: 0001-Show-prompts-after-a-comment-in-the-REPL.patch --]
[-- Type: application/octet-stream, Size: 3785 bytes --]
From 805a1813420c480559c849bc1984f65db3880937 Mon Sep 17 00:00:00 2001
From: Noah Lavine <nlavine@haverford.edu>
Date: Sun, 13 Feb 2011 16:17:11 -0500
Subject: [PATCH] Show prompts after a comment in the REPL
* module/system/repl/repl.scm (next-char, run-repl, meta-reader): if the
current language is Scheme, ignore any characters from a semicolon to
the end of the line, then print a new prompt.
---
module/system/repl/repl.scm | 29 +++++++++++++++++++++--------
1 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/module/system/repl/repl.scm b/module/system/repl/repl.scm
index b135dbb..47e5771 100644
--- a/module/system/repl/repl.scm
+++ b/module/system/repl/repl.scm
@@ -29,6 +29,7 @@
#:use-module (system repl common)
#:use-module (system repl command)
#:use-module (ice-9 control)
+ #:use-module (ice-9 rdelim)
#:export (start-repl run-repl))
\f
@@ -62,11 +63,11 @@
(define meta-command-token (cons 'meta 'command))
-(define (meta-reader read env)
+(define (meta-reader read env semicolon-comments)
(lambda* (#:optional (port (current-input-port)))
(with-input-from-port port
(lambda ()
- (let ((ch (next-char #t)))
+ (let ((ch (next-char #t semicolon-comments)))
(cond ((eof-object? ch)
;; EOF objects are not buffered. It's quite possible
;; to peek an EOF then read something else. It's
@@ -75,6 +76,7 @@
((eqv? ch #\,)
(read-char port)
meta-command-token)
+ ((not ch) *unspecified*)
(else (read port env))))))))
;; repl-reader is a function defined in boot-9.scm, and is replaced by
@@ -82,12 +84,13 @@
;; to be able to re-use the existing readline machinery.
;;
;; Catches read errors, returning *unspecified* in that case.
-(define (prompting-meta-read repl)
+(define (prompting-meta-read repl semicolon-comments)
(catch #t
(lambda ()
(repl-reader (lambda () (repl-prompt repl))
(meta-reader (language-reader (repl-language repl))
- (current-module))))
+ (current-module)
+ semicolon-comments)))
(lambda (key . args)
(case key
((quit)
@@ -146,7 +149,10 @@
(if (null? (cdr (fluid-ref *repl-stack*)))
(repl-welcome repl))
(let prompt-loop ()
- (let ((exp (prompting-meta-read repl)))
+ (let ((exp (prompting-meta-read
+ repl
+ (eq? (repl-language (car (fluid-ref *repl-stack*)))
+ scheme-lang))))
(cond
((eqv? exp *unspecified*)) ; read error, pass
((eq? exp meta-command-token)
@@ -197,16 +203,23 @@
(lambda (k . args)
(abort args))))
#:trap-handler 'disabled)))
- (next-char #f) ;; consume trailing whitespace
+ (next-char #f (eq? (repl-language (car (fluid-ref *repl-stack*)))
+ scheme-lang)) ;; consume trailing whitespace
(prompt-loop))))
(lambda (k status)
status)))
-(define (next-char wait)
+(define scheme-lang (lookup-language 'scheme))
+
+(define (next-char wait semicolon-comments)
(if (or wait (char-ready?))
(let ((ch (peek-char)))
(cond ((eof-object? ch) ch)
- ((char-whitespace? ch) (read-char) (next-char wait))
+ ((and (char=? ch #\;) semicolon-comments)
+ (read-line) #f) ; ignore wait after a newline
+ ((char-whitespace? ch)
+ (read-char)
+ (next-char wait semicolon-comments))
(else ch)))
#f))
--
1.7.4
next prev parent reply other threads:[~2011-02-13 21:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-11 21:15 problem with trailing comment in repl Jose A. Ortega Ruiz
2011-02-12 12:34 ` Andy Wingo
2011-02-12 13:21 ` Jose A. Ortega Ruiz
2011-02-12 14:36 ` Andy Wingo
2011-02-13 15:22 ` Noah Lavine
2011-02-13 19:19 ` Andy Wingo
2011-02-13 21:27 ` Noah Lavine [this message]
2011-02-14 10:09 ` Ludovic Courtès
2011-02-15 2:42 ` Noah Lavine
2011-03-03 22:56 ` Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='AANLkTi=DFDr2nO1WeuxLkWmSO+TO6A=2gwbkOCrOq4E+@mail.gmail.com' \
--to=noah.b.lavine@gmail.com \
--cc=guile-devel@gnu.org \
--cc=jao@gnu.org \
--cc=wingo@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).