From: Andreas Rottmann <a.rottmann@gmx.at>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] R6RS-style block comments
Date: Mon, 05 Oct 2009 15:25:04 +0200 [thread overview]
Message-ID: <877hvaq8gf.fsf@delenn.lan> (raw)
In-Reply-To: <87tyyi6t6c.fsf@gnu.org> ("Ludovic Courtès"'s message of "Fri, 02 Oct 2009 11:28:43 +0200")
[-- Attachment #1: Type: text/plain, Size: 468 bytes --]
ludo@gnu.org (Ludovic Courtès) writes:
> Hi,
>
> Andreas Rottmann <a.rottmann@gmx.at> writes:
>
>> Attached is a patch that extends the read syntax to allow for #| ... |#
>> block comments.
>
> Are there objections to this patch? If no, I’ll apply it.
>
> Note that it makes the reader understand this syntax by default, not via
> a read option.
>
I have attached an updated version of the patch which should apply
cleanly against current HEAD.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: r6rs-block-comments.diff --]
[-- Type: text/x-diff, Size: 3525 bytes --]
From: Andreas Rottmann <a.rottmann@gmx.at>
Subject: [PATCH] Add support for #| ... |# comments
This syntax has been added by R6RS.
---
NEWS | 5 +++++
libguile/read.c | 33 ++++++++++++++++++++-------------
2 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/NEWS b/NEWS
index 66e21de..c2f3bdc 100644
--- a/NEWS
+++ b/NEWS
@@ -412,6 +412,11 @@ actually used this, this behavior may be reinstated via the
#; comments out an entire expression. See SRFI-62 or the R6RS for more
information.
+** Additional syntax for block comments
+
+#| ... |# is now accepted syntax for block comments, in addition to
+#! ... !#.
+
** `make-stack' with a tail-called procedural narrowing argument no longer
works (with compiled procedures)
diff --git a/libguile/read.c b/libguile/read.c
index 07c8d71..10ac08e 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -180,9 +180,9 @@ static SCM *scm_read_hash_procedures;
(((_chr) == 'e') || ((_chr) == 's') || ((_chr) == 'f') \
|| ((_chr) == 'd') || ((_chr) == 'l'))
-/* Read an SCSH block comment. */
-static inline SCM scm_read_scsh_block_comment (int chr, SCM port);
-static SCM scm_read_commented_expression (int chr, SCM port);
+/* Read an SCSH or R6RS block comment. */
+static inline SCM scm_read_block_comment (scm_t_wchar chr, SCM port);
+static SCM scm_read_commented_expression (scm_t_wchar chr, SCM port);
/* Read from PORT until a delimiter (e.g., a whitespace) is read. Return
zero if the whole token fits in BUF, non-zero otherwise. */
@@ -284,7 +284,8 @@ flush_ws (SCM port, const char *eoferr)
eoferr = "read_sharp";
goto goteof;
case '!':
- scm_read_scsh_block_comment (c, port);
+ case '|':
+ scm_read_block_comment (c, port);
break;
case ';':
scm_read_commented_expression (c, port);
@@ -963,9 +964,10 @@ scm_read_guile_bit_vector (scm_t_wchar chr, SCM port)
}
static inline SCM
-scm_read_scsh_block_comment (scm_t_wchar chr, SCM port)
+scm_read_block_comment (scm_t_wchar chr, SCM port)
{
- int bang_seen = 0;
+ int comment_char_seen = 0;
+ int comment_char = (int) chr;
/* We can use the get_byte here because there is no need to get the
locale correct when reading comments. This presumes that
@@ -976,15 +978,19 @@ scm_read_scsh_block_comment (scm_t_wchar chr, SCM port)
int c = scm_get_byte_or_eof (port);
if (c == EOF)
- scm_i_input_error ("skip_block_comment", port,
- "unterminated `#! ... !#' comment", SCM_EOL);
+ {
+ scm_i_input_error ("skip_block_comment", port,
+ "unterminated `#~A ... ~A#' comment",
+ scm_list_2 (SCM_MAKE_CHAR (comment_char),
+ SCM_MAKE_CHAR (comment_char)));
+ }
- if (c == '!')
- bang_seen = 1;
- else if (c == '#' && bang_seen)
+ if (c == comment_char)
+ comment_char_seen = 1;
+ else if (c == '#' && comment_char_seen)
break;
else
- bang_seen = 0;
+ comment_char_seen = 0;
}
return SCM_UNSPECIFIED;
@@ -1163,7 +1169,8 @@ scm_read_sharp (scm_t_wchar chr, SCM port)
case '{':
return (scm_read_extended_symbol (chr, port));
case '!':
- return (scm_read_scsh_block_comment (chr, port));
+ case '|':
+ return (scm_read_block_comment (chr, port));
case ';':
return (scm_read_commented_expression (chr, port));
case '`':
--
tg: (b25aa0b..) t/r6rs-block-comments (depends on: master)
[-- Attachment #3: Type: text/plain, Size: 16 bytes --]
Regards, Rotty
next prev parent reply other threads:[~2009-10-05 13:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-25 21:32 [PATCH] R6RS-style block comments Andreas Rottmann
2009-10-02 9:28 ` Ludovic Courtès
2009-10-05 13:25 ` Andreas Rottmann [this message]
2009-10-05 21:52 ` Andreas Rottmann
2009-10-06 19:33 ` Andy Wingo
2009-10-07 21:46 ` Neil Jerram
2009-10-14 21:47 ` Andreas Rottmann
2009-10-19 20:53 ` Exceptions Ludovic Courtès
2009-10-19 20:49 ` [PATCH] R6RS-style block comments Ludovic Courtès
2009-10-06 21:54 ` Neil Jerram
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=877hvaq8gf.fsf@delenn.lan \
--to=a.rottmann@gmx.at \
--cc=guile-devel@gnu.org \
--cc=ludo@gnu.org \
/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).