On Fri, Aug 30, 2013 at 09:39:19AM +0200, Peter Bex wrote:
> On Fri, Aug 30, 2013 at 01:17:40AM -0600, Matt Gushee wrote:
> > and Chicken by default
> > treats square brackets as equivalent to parentheses. So I wanted to
> > see what would happen if I used csi -no-parentheses-synonyms. But it
> > seems that option has no effect.
> 
> It looks like you've indeed found a bug.  I've done some tests, and
> passing -r5rs-syntax seems to disable the paren synonyms correctly.
> I don't see why a lone -no-parentheses-synonyms shouldn't do the
> job; they access the same parameter behind the scenes.  Anyway, I'll
> look into the code behind this later.  Thanks for reporting it!

It turned out that -no-symbol-escape was also broken, due to an
incorrect overcomplicated 4-way if-expression which determined the
reserved characters depending on whether -no-symbol-escape or
-no-parentheses-synonyms was supplied.

Here's a fix for this, with some regression tests to ensure this won't
break again.

I've hopefully simplified it enough to make it "obviously correct".
I also noticed that even after correcting the test, pipes occurring
inside symbols were still allowed, so I've also fixed this by adding
an additional check (the "sep" check was wrong so I ripped it out).

Cheers,
Peter
-- 
http://www.more-magic.net
>From 4f5f578e4df69e535111e22ec41aa7abf8fe059f Mon Sep 17 00:00:00 2001
From: Peter Bex <[email protected]>
Date: Fri, 30 Aug 2013 16:51:17 +0200
Subject: [PATCH] Fix handling of -no-symbol-escape and
 -no-parentheses-synonyms

Add some basic tests for the effect of the underlying parameters on READ, and 
fix the manual which mentioned a STYLE argument for -no-parentheses-synonyms
Thanks to Matt Gushee for reporting this bug.
---
 library.scm                  | 13 +++++--------
 manual/Using the compiler    |  2 +-
 manual/Using the interpreter |  2 +-
 tests/library-tests.scm      | 23 +++++++++++++++++++++++
 4 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/library.scm b/library.scm
index 5c101e3..2d56328 100644
--- a/library.scm
+++ b/library.scm
@@ -2747,9 +2747,11 @@ EOF
                         (if (and skw (eq? ksp #:suffix))
                             (k (##sys#reverse-list->string (cdr lst)) #t)
                             (k (##sys#reverse-list->string lst) pkw)))
+                        ((memq c reserved-characters)
+                         (reserved-character c))
                        (else
                         (let ((c (##sys#read-char-0 port)))
-                          (case (and sep c)
+                          (case c
                             ((#\|) 
                              (let ((part (r-string #\|)))
                                (loop (append (##sys#fast-reverse 
(##sys#string->list part)) lst)
@@ -2858,13 +2860,8 @@ EOF
 
           ; now have the state to make a decision.
           (set! reserved-characters
-               (if psp
-                   (if sep
-                       '()
-                       '(#\[ #\] #\{ #\}) )
-                   (if sep
-                       '(#\|)
-                       '(#\[ #\] #\{ #\} #\|))))
+                (append (if (not psp) '(#\[ #\] #\{ #\}) '())
+                        (if (not sep) '(#\|) '())))
 
          (r-spaces)
          (let* ((c (##sys#peek-char-0 port))
diff --git a/manual/Using the compiler b/manual/Using the compiler
index 1bfc36c..9807eaa 100644
--- a/manual/Using the compiler 
+++ b/manual/Using the compiler 
@@ -102,7 +102,7 @@ the source text should be read from standard input.
 
 ; -no-module-registration : Do not generate module-registration code in the 
compiled code. This is only needed if you want to use an import library that is 
generated by other means (manually, for example).
 
-; -no-parentheses-synonyms STYLE : Disables list delimiter synonyms, [..] and 
{...} for (...).
+; -no-parentheses-synonyms : Disables list delimiter synonyms, [..] and {...} 
for (...).
 
 ; -no-procedure-checks : disable procedure call checks
 
diff --git a/manual/Using the interpreter b/manual/Using the interpreter
index 8d6d699..cec50aa 100644
--- a/manual/Using the interpreter      
+++ b/manual/Using the interpreter      
@@ -41,7 +41,7 @@ The options recognized by the interpreter are:
 
 ; -n  -no-init : Do not load initialization-file. If this option is not given 
and the file {{$HOME/.csirc}} exists, then it is loaded before the 
read-eval-print loop commences.
 
-;     -no-parentheses-synonyms STYLE : Disables list delimiter synonyms, [..] 
and {...} for (...).
+;     -no-parentheses-synonyms : Disables list delimiter synonyms, [..] and 
{...} for (...).
 
 ;     -no-symbol-escape : Disables support for escaped symbols, the |...| form.
 
diff --git a/tests/library-tests.scm b/tests/library-tests.scm
index 24bbc1d..8f3f07b 100644
--- a/tests/library-tests.scm
+++ b/tests/library-tests.scm
@@ -283,6 +283,29 @@
   (assert (string=? "aBc" (symbol->string (with-input-from-string "|aBc|" 
read))))
   (assert (string=? "aBc" (symbol->string (with-input-from-string "a\\Bc" 
read)))))
 
+(parameterize ((symbol-escape #f))
+  (assert (string=? "aBc" (symbol->string (with-input-from-string "aBc" 
read))))
+  (assert-fail (with-input-from-string "|aBc|" read))
+  (assert-fail (with-input-from-string "a|Bc" read)))
+(parameterize ((symbol-escape #t))
+  (assert (string=? "aBc" (symbol->string (with-input-from-string "aBc" 
read))))
+  (assert (string=? "aBc" (symbol->string (with-input-from-string "|aBc|" 
read))))
+  (assert (string=? "aB c" (symbol->string (with-input-from-string "|aB c|" 
read))))
+  ;; The following is an extension/generalisation of r7RS
+  (assert (string=? "aBc" (symbol->string (with-input-from-string "a|Bc|" 
read))))
+  ;; "Unterminated string" (unterminated identifier?)
+  (assert-fail (with-input-from-string "a|Bc" read)))
+
+;;; Paren synonyms
+
+(parameterize ((parentheses-synonyms #f))
+  (assert (eq? '() (with-input-from-string "()" read)))
+  (assert-fail (with-input-from-string "[]" read))
+  (assert-fail (with-input-from-string "{}" read)))
+(parameterize ((parentheses-synonyms #t))
+  (assert (eq? '() (with-input-from-string "()" read)))
+  (assert (eq? '() (with-input-from-string "[]" read)))
+  (assert (eq? '() (with-input-from-string "{}" read))))
 
 ;;; keywords
 
-- 
1.7.12

_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to