unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mikael Djurfeldt <mikael@djurfeldt.com>
To: guile-devel <guile-devel@gnu.org>
Cc: Mark H Weaver <mhw@netris.org>
Subject: Re: Precedence for reader extensions
Date: Tue, 19 Feb 2013 11:14:03 +0100	[thread overview]
Message-ID: <CAA2Xvw+QsHP4jPNYW_GpnHsiRBKuojDW=1f=+AtC=JQVZ6NXLQ@mail.gmail.com> (raw)
In-Reply-To: <87mwv1nqns.fsf@tines.lan>

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

On Tue, Feb 19, 2013 at 12:33 AM, Mark H Weaver <mhw@netris.org> wrote:
> Mikael Djurfeldt <mikael@djurfeldt.com> writes:
>> I propose to simplify this to only two levels:
>>
>> 1. %read-hash-procedures
>> 2. predefined syntax

It turns out that the change I propose above was already implemented
in read.c.  The effect just wasn't visible due to a bug in flush_ws
which caused all #! to be erroneously removed if they exist as the
outermost expression.

In the attached diff, I've fixed the flush_ws bug and cleaned up some
garbage code in scm_read_sharp which was unreachable.

Can I push this into the repository?

> I don't think this would be sufficient.  The problem is that tokens of
> the form "#!<symbol><delimiter>" have become standardized.  To name a
> few examples, both R6RS and R7RS define the reader directives
> #!fold-case and #!no-fold-case, R6RS has #!r6rs, and SRFI-105 has
> #!curly-infix.  Guile also has #! ... !# block comments to help with the
> handling of executable scripts.

In what sense is it not sufficient?  In any case: The present diff
doesn't remove any functionality or make performance worse.  It only
removes some inconsistent behavior.  At the same time it allows
support for mit-scheme #!optional and #!rest.

Best regards,
Mikael D.

[-- Attachment #2: reader-fix.diff --]
[-- Type: application/octet-stream, Size: 2148 bytes --]

diff --git a/libguile/read.c b/libguile/read.c
index 7c003b4..71eae32 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -356,7 +356,13 @@ flush_ws (SCM port, scm_t_read_opts *opts, const char *eoferr)
 	break;
 
       case '#':
-	switch (c = scm_getc_unlocked (port))
+	c = scm_getc_unlocked (port);
+	if (scm_is_true (scm_procedure_p (scm_get_hash_procedure (c))))
+	  {
+	    scm_ungetc_unlocked (c, port);
+	    return '#';
+	  }
+	switch (c)
 	  {
 	  case EOF:
 	    eoferr = "read_sharp";
@@ -368,12 +374,8 @@ flush_ws (SCM port, scm_t_read_opts *opts, const char *eoferr)
 	    scm_read_commented_expression (c, port, opts);
 	    break;
 	  case '|':
-	    if (scm_is_false (scm_get_hash_procedure (c)))
-	      {
-		scm_read_r6rs_block_comment (c, port);
-		break;
-	      }
-	    /* fall through */
+	    scm_read_r6rs_block_comment (c, port);
+	    break;
 	  default:
 	    scm_ungetc_unlocked (c, port);
 	    return '#';
@@ -1626,6 +1628,8 @@ scm_read_sharp (scm_t_wchar chr, SCM port, scm_t_read_opts *opts,
       return (scm_read_extended_symbol (chr, port));
     case '!':
       return (scm_read_shebang (chr, port, opts));
+    case '|':
+      return scm_read_r6rs_block_comment (chr, port);
     case ';':
       return (scm_read_commented_expression (chr, port, opts));
     case '`':
@@ -1635,23 +1639,8 @@ scm_read_sharp (scm_t_wchar chr, SCM port, scm_t_read_opts *opts,
     case 'n':
       return (scm_read_nil (chr, port, opts));
     default:
-      result = scm_read_sharp_extension (chr, port, opts);
-      if (scm_is_eq (result, SCM_UNSPECIFIED))
-	{
-	  /* To remain compatible with 1.8 and earlier, the following
-	     characters have lower precedence than `read-hash-extend'
-	     characters.  */
-	  switch (chr)
-	    {
-	    case '|':
-	      return scm_read_r6rs_block_comment (chr, port);
-	    default:
-	      scm_i_input_error (FUNC_NAME, port, "Unknown # object: ~S",
-				 scm_list_1 (SCM_MAKE_CHAR (chr)));
-	    }
-	}
-      else
-	return result;
+      scm_i_input_error (FUNC_NAME, port, "Unknown # object: ~S",
+			 scm_list_1 (SCM_MAKE_CHAR (chr)));
     }
 
   return SCM_UNSPECIFIED;

  reply	other threads:[~2013-02-19 10:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-18 21:05 Precedence for reader extensions Mikael Djurfeldt
2013-02-18 21:07 ` Mikael Djurfeldt
2013-02-18 21:26 ` Mikael Djurfeldt
2013-02-18 21:42   ` Mikael Djurfeldt
2013-02-18 23:33 ` Mark H Weaver
2013-02-19 10:14   ` Mikael Djurfeldt [this message]
2013-02-19 15:41     ` Mark H Weaver
2013-02-19 16:42       ` Mikael Djurfeldt
2013-02-19 16:58         ` Mikael Djurfeldt
2013-02-20 14:21           ` Ludovic Courtès
2013-02-22  2:52           ` Mark H Weaver
2013-02-22  9:36             ` Mikael Djurfeldt
2013-02-22 15:45               ` Ludovic Courtès
2013-02-22 15:54             ` Ludovic Courtès
2013-02-19 23:51         ` Mikael Djurfeldt

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='CAA2Xvw+QsHP4jPNYW_GpnHsiRBKuojDW=1f=+AtC=JQVZ6NXLQ@mail.gmail.com' \
    --to=mikael@djurfeldt.com \
    --cc=guile-devel@gnu.org \
    --cc=mhw@netris.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).