unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Julian Graham" <joolean@gmail.com>
To: "Guile Development" <guile-devel@gnu.org>
Subject: SRFI-88-style keywords
Date: Fri, 2 Nov 2007 20:14:19 -0400	[thread overview]
Message-ID: <2bc5f8210711021714t4b3c3743v7dc76a882916be42@mail.gmail.com> (raw)

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

Hi Guilers,

I was looking at some SRFIs recently (specifically SRFIs 88, 89, and
90), and I noticed that Guile could support all three of them pretty
easily if the reader allowed self-quoting keywords in which the colon
comes at the end, a la SRFI-88.  The default reader behavior is to
only parse tokens as keywords if they begin with #: (e.g., #:foo), but
you can modify this behavior by setting the reader option (keywords
'prefix), which gets you keywords that start with just the colon
(e.g., :foo).  What if we added another reader option, say, (keywords
'postfix), which would recognize SRFI-88-style keywords?

I've attached a (slightly clumsy) patch against HEAD that adds this
functionality to read.c.  I know this is unsolicited, but I think it'd
be fairly useful in terms of compatibility.


Regards,
Julian

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: postfix-keywords.HEAD.patch --]
[-- Type: text/x-patch; name=postfix-keywords.HEAD.patch, Size: 1990 bytes --]

Index: read.c
===================================================================
RCS file: /sources/guile/guile/guile-core/libguile/read.c,v
retrieving revision 1.128
diff -a -u -r1.128 read.c
--- read.c	17 Oct 2007 21:56:10 -0000	1.128
+++ read.c	2 Nov 2007 23:54:18 -0000
@@ -53,6 +53,7 @@
 
 SCM_GLOBAL_SYMBOL (scm_sym_dot, ".");
 SCM_SYMBOL (scm_keyword_prefix, "prefix");
+SCM_SYMBOL (scm_keyword_postfix, "postfix");
 
 scm_t_option scm_read_opts[] = {
   { SCM_OPTION_BOOLEAN, "copy", 0,
@@ -62,7 +63,7 @@
   { SCM_OPTION_BOOLEAN, "case-insensitive", 0,
     "Convert symbols to lower case."},
   { SCM_OPTION_SCM, "keywords", SCM_UNPACK (SCM_BOOL_F),
-    "Style of keyword recognition: #f or 'prefix."},
+    "Style of keyword recognition: #f, 'prefix, or 'postfix."},
 #if SCM_ENABLE_ELISP
   { SCM_OPTION_BOOLEAN, "elisp-vectors", 0,
     "Support Elisp vector syntax, namely `[...]'."},
@@ -532,6 +533,8 @@
 {
   SCM result, str = SCM_EOL;
   int overflow = 0;
+  int postfix = scm_is_eq (SCM_PACK (SCM_KEYWORD_STYLE), scm_keyword_postfix);
+		  
   char buffer[READER_BUFFER_SIZE];
   size_t read = 0;
 
@@ -549,12 +552,26 @@
     {
       str = scm_string_concatenate (scm_reverse_x (str, SCM_EOL));
       result = scm_string_to_symbol (str);
+      
+      if (postfix)
+	{
+	  size_t l = scm_c_string_length (str) - 1;
+	  if (l && scm_is_true (scm_char_eq_p (scm_c_string_ref (str, l),
+					       SCM_MAKE_CHAR (':'))))
+	    result = scm_from_locale_keywordn (scm_i_string_chars (str), l);
+	}
     }
   else
+    {
+
     /* For symbols smaller than `sizeof (buffer)', we don't need to recur to
        Scheme strings.  Therefore, we only create one Scheme object (a
        symbol) per symbol read.  */
-    result = scm_from_locale_symboln (buffer, read);
+      if (postfix && read > 1 && buffer[read - 1] == ':')
+	result = scm_from_locale_keywordn (buffer, read - 1);
+      else 
+	result = scm_from_locale_symboln (buffer, read);
+    }
 
   return result;
 }

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

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel

             reply	other threads:[~2007-11-03  0:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-03  0:14 Julian Graham [this message]
2007-11-03 14:37 ` SRFI-88-style keywords Ludovic Courtès
2008-04-15 18:08 ` Ludovic Courtès
2008-04-15 18:30   ` Julian Graham
2008-04-15 18:56     ` Ludovic Courtès
2008-04-26 19:35   ` Ludovic Courtès
2008-04-27  5:31     ` Julian Graham
2008-04-27 11:22       ` Ludovic Courtès

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=2bc5f8210711021714t4b3c3743v7dc76a882916be42@mail.gmail.com \
    --to=joolean@gmail.com \
    --cc=guile-devel@gnu.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).