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: [PATCH] R6RS-style block comments Date: Sat, 25 Jul 2009 23:32:14 +0200 Message-ID: <87hbx0sb35.fsf@delenn.lan> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1248557559 8910 80.91.229.12 (25 Jul 2009 21:32:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 25 Jul 2009 21:32:39 +0000 (UTC) To: Guile Developers Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Jul 25 23:32:32 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 1MUor1-0003wu-AD for guile-devel@m.gmane.org; Sat, 25 Jul 2009 23:32:31 +0200 Original-Received: from localhost ([127.0.0.1]:52189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MUor0-0000k5-OQ for guile-devel@m.gmane.org; Sat, 25 Jul 2009 17:32:30 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MUoqu-0000jq-KZ for guile-devel@gnu.org; Sat, 25 Jul 2009 17:32:24 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MUoqq-0000jW-6E for guile-devel@gnu.org; Sat, 25 Jul 2009 17:32:24 -0400 Original-Received: from [199.232.76.173] (port=34554 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MUoqq-0000jT-22 for guile-devel@gnu.org; Sat, 25 Jul 2009 17:32:20 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]:56653) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MUoqp-0001d7-Ey for guile-devel@gnu.org; Sat, 25 Jul 2009 17:32:19 -0400 Original-Received: (qmail invoked by alias); 25 Jul 2009 21:32:17 -0000 Original-Received: from 83-215-154-5.hage.dyn.salzburg-online.at (EHLO nathot.lan) [83.215.154.5] by mail.gmx.net (mp038) with SMTP; 25 Jul 2009 23:32:17 +0200 X-Authenticated: #3102804 X-Provags-ID: V01U2FsdGVkX19fkb4+9I9fNdggCU/CUDH/o9f6ywEY2YynKp6pjS jyL3ARiku1Wg/3 Original-Received: by nathot.lan (Postfix, from userid 121) id 4F3603A691; Sat, 25 Jul 2009 23:32:17 +0200 (CEST) Original-Received: from delenn.lan (delenn.lan [192.168.1.11]) by nathot.lan (Postfix) with ESMTP id BB9E93A672 for ; Sat, 25 Jul 2009 23:32:15 +0200 (CEST) Original-Received: by delenn.lan (Postfix, from userid 1000) id E64DE74E8F; Sat, 25 Jul 2009 23:32:14 +0200 (CEST) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.96 (gnu/linux) X-Y-GMX-Trusted: 0 X-FuHaFi: 0.88 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:8966 Archived-At: --=-=-= Attached is a patch that extends the read syntax to allow for #| ... |# block comments. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=t_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 | 35 +++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index 445bb1c..e58915e 100644 --- a/NEWS +++ b/NEWS @@ -356,6 +356,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 bd028ea..46d4582 100644 --- a/libguile/read.c +++ b/libguile/read.c @@ -182,8 +182,8 @@ static SCM *scm_read_hash_procedures; (((_chr) <= UCHAR_MAX) ? tolower (_chr) : (_chr)) -/* Read an SCSH block comment. */ -static inline SCM scm_read_scsh_block_comment (int chr, SCM port); +/* Read an SCSH or R6RS block comment. */ +static inline SCM scm_read_block_comment (int chr, SCM port); static SCM scm_read_commented_expression (int chr, SCM port); /* Read from PORT until a delimiter (e.g., a whitespace) is read. Return @@ -258,7 +258,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); @@ -928,24 +929,29 @@ scm_read_guile_bit_vector (int chr, SCM port) } static inline SCM -scm_read_scsh_block_comment (int chr, SCM port) +scm_read_block_comment (int chr, SCM port) { - int bang_seen = 0; - + int comment_char_seen = 0; + int comment_char = chr; + for (;;) { int c = scm_getc (port); if (c == EOF) - scm_i_input_error ("skip_block_comment", port, - "unterminated `#! ... !#' comment", SCM_EOL); - - if (c == '!') - bang_seen = 1; - else if (c == '#' && bang_seen) + { + 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 == comment_char) + comment_char_seen = 1; + else if (c == '#' && comment_char_seen) break; else - bang_seen = 0; + comment_char_seen = 0; } return SCM_UNSPECIFIED; @@ -1127,7 +1133,8 @@ scm_read_sharp (int 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: (74deff3..) t/r6rs-block-comments (depends on: master) --=-=-= Cheers, Rotty -- Andreas Rottmann -- --=-=-=--