From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Rottmann Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] R6RS-style block comments Date: Mon, 05 Oct 2009 15:25:04 +0200 Message-ID: <877hvaq8gf.fsf@delenn.lan> References: <87hbx0sb35.fsf@delenn.lan> <87tyyi6t6c.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1254749366 26944 80.91.229.12 (5 Oct 2009 13:29:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 5 Oct 2009 13:29:26 +0000 (UTC) Cc: guile-devel@gnu.org To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Oct 05 15:29:22 2009 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Muncu-000397-Ki for guile-devel@m.gmane.org; Mon, 05 Oct 2009 15:29:21 +0200 Original-Received: from localhost ([127.0.0.1]:39425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Muncu-0005Uk-La for guile-devel@m.gmane.org; Mon, 05 Oct 2009 09:29:20 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MunZ2-0004C4-3d for guile-devel@gnu.org; Mon, 05 Oct 2009 09:25:20 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MunYx-0004Am-E7 for guile-devel@gnu.org; Mon, 05 Oct 2009 09:25:19 -0400 Original-Received: from [199.232.76.173] (port=52172 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MunYw-0004Ai-L7 for guile-devel@gnu.org; Mon, 05 Oct 2009 09:25:14 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]:56313) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MunYw-00048X-25 for guile-devel@gnu.org; Mon, 05 Oct 2009 09:25:14 -0400 Original-Received: (qmail invoked by alias); 05 Oct 2009 13:25:11 -0000 Original-Received: from 83-215-154-5.hage.dyn.salzburg-online.at (EHLO nathot.lan) [83.215.154.5] by mail.gmx.net (mp046) with SMTP; 05 Oct 2009 15:25:11 +0200 X-Authenticated: #3102804 X-Provags-ID: V01U2FsdGVkX18ib4RsQtwiV6UPOICbbsrCWeJv0ddCYAh+ytgvVO LlUtr+s1M2Cxqg Original-Received: by nathot.lan (Postfix, from userid 121) id EEDCF3A688; Mon, 5 Oct 2009 15:25:10 +0200 (CEST) Original-Received: from delenn.lan (delenn.lan [192.168.1.11]) by nathot.lan (Postfix) with ESMTP id 5281A3A672; Mon, 5 Oct 2009 15:25:06 +0200 (CEST) Original-Received: by delenn.lan (Postfix, from userid 1000) id 3F13174EB0; Mon, 5 Oct 2009 15:25:04 +0200 (CEST) In-Reply-To: <87tyyi6t6c.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Fri, 02 Oct 2009 11:28:43 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-Y-GMX-Trusted: 0 X-FuHaFi: 0.74 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:9440 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Hi, > > Andreas Rottmann writes: > >> Attached is a patch that extends the read syntax to allow for #| ... |# >> block comments. > > Are there objections to this patch? If no, I=E2=80=99ll 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=r6rs-block-comments.diff From: Andreas Rottmann 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) --=-=-= Regards, Rotty --=-=-=--