unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] R6RS-style block comments
@ 2009-07-25 21:32 Andreas Rottmann
  2009-10-02  9:28 ` Ludovic Courtès
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Rottmann @ 2009-07-25 21:32 UTC (permalink / raw)
  To: Guile Developers

[-- Attachment #1: Type: text/plain, Size: 90 bytes --]


Attached is a patch that extends the read syntax to allow for #| ... |#
block comments.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: t_r6rs-block-comments.diff --]
[-- Type: text/x-diff, Size: 3099 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 |   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)

[-- Attachment #3: Type: text/plain, Size: 62 bytes --]


Cheers, Rotty
-- 
Andreas Rottmann -- <http://rotty.yi.org/>

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-10-19 20:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).