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

* Re: [PATCH] R6RS-style block comments
  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-06 21:54   ` Neil Jerram
  0 siblings, 2 replies; 10+ messages in thread
From: Ludovic Courtès @ 2009-10-02  9:28 UTC (permalink / raw)
  To: guile-devel

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.

Thanks,
Ludo’.





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

* Re: [PATCH] R6RS-style block comments
  2009-10-02  9:28 ` Ludovic Courtès
@ 2009-10-05 13:25   ` Andreas Rottmann
  2009-10-05 21:52     ` Andreas Rottmann
  2009-10-19 20:49     ` [PATCH] R6RS-style block comments Ludovic Courtès
  2009-10-06 21:54   ` Neil Jerram
  1 sibling, 2 replies; 10+ messages in thread
From: Andreas Rottmann @ 2009-10-05 13:25 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

[-- 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

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

* Re: [PATCH] R6RS-style block comments
  2009-10-05 13:25   ` Andreas Rottmann
@ 2009-10-05 21:52     ` Andreas Rottmann
  2009-10-06 19:33       ` Andy Wingo
  2009-10-19 20:49     ` [PATCH] R6RS-style block comments Ludovic Courtès
  1 sibling, 1 reply; 10+ messages in thread
From: Andreas Rottmann @ 2009-10-05 21:52 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

Andreas Rottmann <a.rottmann@gmx.at> writes:

> 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.
>
I just noticed that the patch breaks "reader.test", as that hardcodes
the message exception message format string (eeew!) -- if you apply that
patch, you might want to change that string as well.

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




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

* Re: [PATCH] R6RS-style block comments
  2009-10-05 21:52     ` Andreas Rottmann
@ 2009-10-06 19:33       ` Andy Wingo
  2009-10-07 21:46         ` Neil Jerram
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Wingo @ 2009-10-06 19:33 UTC (permalink / raw)
  To: Andreas Rottmann; +Cc: Ludovic Courtès, guile-devel

On Mon 05 Oct 2009 23:52, Andreas Rottmann <a.rottmann@gmx.at> writes:

> I just noticed that the patch breaks "reader.test", as that hardcodes
> the message exception message format string (eeew!) -- if you apply that
> patch, you might want to change that string as well.

Oh man, at some point we have some pain coming, switching to
srfi-35/r6rs exceptions. We mentioned it in August and decided to punt
indefinitely -- though should someone be interested, help would be
welcome ;-)

A
-- 
http://wingolog.org/




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

* Re: [PATCH] R6RS-style block comments
  2009-10-02  9:28 ` Ludovic Courtès
  2009-10-05 13:25   ` Andreas Rottmann
@ 2009-10-06 21:54   ` Neil Jerram
  1 sibling, 0 replies; 10+ messages in thread
From: Neil Jerram @ 2009-10-06 21:54 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

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.

As long as it's still possible to override with (read-hash-extend #\|
...), fine.

       Neil




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

* Re: [PATCH] R6RS-style block comments
  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
  0 siblings, 2 replies; 10+ messages in thread
From: Neil Jerram @ 2009-10-07 21:46 UTC (permalink / raw)
  To: Andy Wingo; +Cc: Ludovic Courtès, guile-devel

Andy Wingo <wingo@pobox.com> writes:

> Oh man, at some point we have some pain coming, switching to
> srfi-35/r6rs exceptions. We mentioned it in August and decided to punt
> indefinitely -- though should someone be interested, help would be
> welcome ;-)

Yeah, we should do that.  Here's an outline design.

- Core concept is that libguile exceptions are srfi-34/srfi-35 objects.
  (I haven't yet checked for detailed changes between srfi-34/srfi-35
  and r6rs.  Are there any?)

- Back compatibility with traditional (key . args) information is
  achieved by having fields in the exception object that carry this
  information.

- There is a new most-fundamental primitive for raising an exception,
  say scm_primitive_raise, which can take both 34/35 type+fields, and
  the traditional (key . args), and constructs a 34/35 object that
  encapsulates all that.

- throw maps on to scm_primitive_raise with an `unspecified throw'
  34/35 type.

- error maps on to scm_primitive_raise with an `unspecified error'
  34/35 type.

- libguile-generated errors/exceptions map on to scm_primitive_raise
  with the most appropriate srfi-35 type, fields for that type, and the
  traditional (key . args) info.

- libguile's primitive exception-handling is modified so that it just
  calls the handler with the scm_primitive_raise object -
  i.e. implements the semantics of with-exception-handler.

- catch and scm_*_catch_* are modified so that they wrap the supplied
  handler procs in a wrapper that extracts the traditional (key . args)
  from the raise object, and passes those to the handler proc.

How does that sound?  Have I missed any important details?

Regards,
        Neil




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

* Re: [PATCH] R6RS-style block comments
  2009-10-07 21:46         ` Neil Jerram
@ 2009-10-14 21:47           ` Andreas Rottmann
  2009-10-19 20:53           ` Exceptions Ludovic Courtès
  1 sibling, 0 replies; 10+ messages in thread
From: Andreas Rottmann @ 2009-10-14 21:47 UTC (permalink / raw)
  To: Neil Jerram; +Cc: Andy Wingo, Ludovic Courtès, guile-devel

Neil Jerram <neil@ossau.uklinux.net> writes:

> Andy Wingo <wingo@pobox.com> writes:
>
>> Oh man, at some point we have some pain coming, switching to
>> srfi-35/r6rs exceptions. We mentioned it in August and decided to punt
>> indefinitely -- though should someone be interested, help would be
>> welcome ;-)
>
> Yeah, we should do that.  Here's an outline design.
>
> - Core concept is that libguile exceptions are srfi-34/srfi-35 objects.
>   (I haven't yet checked for detailed changes between srfi-34/srfi-35
>   and r6rs.  Are there any?)
>
SRFI-34 is compatible with R6RS, but SRFI-35 is not; I'm not sure wether
they are fundamentally incompatible (i.e. neither is implementable on
top of the other).

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




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

* Re: [PATCH] R6RS-style block comments
  2009-10-05 13:25   ` Andreas Rottmann
  2009-10-05 21:52     ` Andreas Rottmann
@ 2009-10-19 20:49     ` Ludovic Courtès
  1 sibling, 0 replies; 10+ messages in thread
From: Ludovic Courtès @ 2009-10-19 20:49 UTC (permalink / raw)
  To: guile-devel

Hello!

This is finally in:
http://git.savannah.gnu.org/cgit/guile.git/commit/?id=620c89651ae54f8f35c3d0926f8c2c36c3fdd174 .

This required some more work to handle nested comments (as specified),
and to make it possible to override the syntax with ‘read-hash-extend’
as Neil suggested.

Thanks,
Ludo’.





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

* Exceptions
  2009-10-07 21:46         ` Neil Jerram
  2009-10-14 21:47           ` Andreas Rottmann
@ 2009-10-19 20:53           ` Ludovic Courtès
  1 sibling, 0 replies; 10+ messages in thread
From: Ludovic Courtès @ 2009-10-19 20:53 UTC (permalink / raw)
  To: guile-devel

Hello,

Neil Jerram <neil@ossau.uklinux.net> writes:

> Andy Wingo <wingo@pobox.com> writes:
>
>> Oh man, at some point we have some pain coming, switching to
>> srfi-35/r6rs exceptions. We mentioned it in August and decided to punt
>> indefinitely -- though should someone be interested, help would be
>> welcome ;-)
>
> Yeah, we should do that.  Here's an outline design.

To me this looks like a post-2.0 thing, because it may be quite
intrusive.

Providing backward compatibility is going to be difficult, e.g.,
providing the ability to observe exception /messages/ and do nasty
things like ‘pass-if-exception’ does.

Thanks,
Ludo’.





^ permalink raw reply	[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).