unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] treat curly-brackets as delimiter
@ 2012-03-13  6:00 Nala Ginrut
  0 siblings, 0 replies; only message in thread
From: Nala Ginrut @ 2012-03-13  6:00 UTC (permalink / raw)
  To: guile-devel


[-- Attachment #1.1: Type: text/plain, Size: 357 bytes --]

According to previous discussion about Sweet expression, we should treat
curly-brackets as delimiter, say:
{+ 1 1} ==> 2
This patch added an option to read-option to enable this. And the patch
will cause Guile treats curly-brackets as delimiter in default.
We don't see any harm for this till now. But one may disable it with
read-option as will.

Regards.

[-- Attachment #1.2: Type: text/html, Size: 423 bytes --]

[-- Attachment #2: 0001-add-SCM_CURLY_BRACKETS_P.patch --]
[-- Type: text/x-patch, Size: 808 bytes --]

From 289a58122780e77968cf3e0d2ade1f786d344b1d Mon Sep 17 00:00:00 2001
From: NalaGinrut <NalaGinrut@gmail.com>
Date: Tue, 13 Mar 2012 13:53:05 +0800
Subject: [PATCH 1/2] add SCM_CURLY_BRACKETS_P

---
 libguile/private-options.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libguile/private-options.h b/libguile/private-options.h
index 9d2d43c..637a8a4 100644
--- a/libguile/private-options.h
+++ b/libguile/private-options.h
@@ -67,7 +67,7 @@ SCM_INTERNAL scm_t_option scm_read_opts[];
 #define SCM_R6RS_ESCAPES_P     scm_read_opts[4].val
 #define SCM_SQUARE_BRACKETS_P  scm_read_opts[5].val
 #define SCM_HUNGRY_EOL_ESCAPES_P scm_read_opts[6].val
-
+#define SCM_CURLY_BRACKETS_P   scm_read_opts[7].val
 #define SCM_N_READ_OPTIONS 6
 
 #endif  /* PRIVATE_OPTIONS */ 
-- 
1.7.0.4


[-- Attachment #3: 0002-treat-curly-brackets-as-delimiter-in-default.patch --]
[-- Type: text/x-patch, Size: 2874 bytes --]

From 5ee33a6a4516b24bef365dc441f563c129fb602a Mon Sep 17 00:00:00 2001
From: NalaGinrut <NalaGinrut@gmail.com>
Date: Tue, 13 Mar 2012 13:54:03 +0800
Subject: [PATCH 2/2] treat curly-brackets as delimiter in default

---
 libguile/read.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/libguile/read.c b/libguile/read.c
index bbaf3f6..57f35e5 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -78,6 +78,8 @@ scm_t_option scm_read_opts[] = {
     "Treat `[' and `]' as parentheses, for R6RS compatibility."},
   { SCM_OPTION_BOOLEAN, "hungry-eol-escapes", 0,
     "In strings, consume leading whitespace after an escaped end-of-line."},
+  { SCM_OPTION_BOOLEAN, "curly-brackets", 1,
+    "Treat `{' and `}' as parentheses, for Sweet-Exp compatibility."},
   { 0, },
 };
 
@@ -186,7 +188,8 @@ scm_i_read_hash_procedures_set_x (SCM value)
 #define CHAR_IS_R5RS_DELIMITER(c)				\
   (CHAR_IS_BLANK (c)						\
    || (c == ')') || (c == '(') || (c == ';') || (c == '"')      \
-   || (SCM_SQUARE_BRACKETS_P && ((c == '[') || (c == ']'))))
+   || (SCM_SQUARE_BRACKETS_P && ((c == '[') || (c == ']')))	\
+   || (SCM_CURLY_BRACKETS_P && ((c == '{') || (c == '}'))))
 
 #define CHAR_IS_DELIMITER  CHAR_IS_R5RS_DELIMITER
 
@@ -373,7 +376,7 @@ scm_read_sexp (scm_t_wchar chr, SCM port)
 {
   int c;
   SCM tmp, tl, ans = SCM_EOL;
-  const int terminating_char = ((chr == '[') ? ']' : ')');
+  const int terminating_char = ((chr == '[') ? ']' : ((chr == '{') ? '}' : ')'));
 
   /* Need to capture line and column numbers here. */
   long line = SCM_LINUM (port);
@@ -405,7 +408,9 @@ scm_read_sexp (scm_t_wchar chr, SCM port)
     {
       SCM new_tail;
 
-      if (c == ')' || (SCM_SQUARE_BRACKETS_P && c == ']'))
+      if (c == ')'
+	  || (SCM_SQUARE_BRACKETS_P && c == ']')
+	  || (SCM_CURLY_BRACKETS_P && c == '}'))
         scm_i_input_error (FUNC_NAME, port,
                            "in pair: mismatched close paren: ~A",
                            scm_list_1 (SCM_MAKE_CHAR (c)));
@@ -1449,6 +1454,10 @@ scm_read_expression (SCM port)
           if (!SCM_SQUARE_BRACKETS_P)
             return (scm_read_mixed_case_symbol (chr, port));
           /* otherwise fall through */
+	case '{':
+          if (!SCM_CURLY_BRACKETS_P)
+            return (scm_read_mixed_case_symbol (chr, port));
+	  /* otherwise fall through */
 	case '(':
 	  return (scm_read_sexp (chr, port));
 	case '"':
@@ -1475,6 +1484,10 @@ scm_read_expression (SCM port)
           if (SCM_SQUARE_BRACKETS_P)
             scm_i_input_error (FUNC_NAME, port, "unexpected \"]\"", SCM_EOL);
           /* otherwise fall through */
+	case '}':
+          if (SCM_CURLY_BRACKETS_P)
+            scm_i_input_error (FUNC_NAME, port, "unexpected \"}\"", SCM_EOL);
+          /* otherwise fall through */
 	case EOF:
 	  return SCM_EOF_VAL;
 	case ':':
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2012-03-13  6:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-13  6:00 [PATCH] treat curly-brackets as delimiter Nala Ginrut

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