unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* SRFI-88-style keywords
@ 2007-11-03  0:14 Julian Graham
  2007-11-03 14:37 ` Ludovic Courtès
  2008-04-15 18:08 ` Ludovic Courtès
  0 siblings, 2 replies; 8+ messages in thread
From: Julian Graham @ 2007-11-03  0:14 UTC (permalink / raw)
  To: Guile Development

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

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

end of thread, other threads:[~2008-04-27 11:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-03  0:14 SRFI-88-style keywords Julian Graham
2007-11-03 14:37 ` 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

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