guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] branch master updated: Fix reading #!!#


From: Andy Wingo
Subject: [Guile-commits] branch master updated: Fix reading #!!#
Date: Sun, 07 Mar 2021 14:19:05 -0500

This is an automated email from the git hooks/post-receive script.

wingo pushed a commit to branch master
in repository guile.

The following commit(s) were added to refs/heads/master by this push:
     new cad6094  Fix reading #!!#
cad6094 is described below

commit cad6094cbc15e78bce2384a5af754bc841ca9127
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Sun Mar 7 19:59:01 2021 +0100

    Fix reading #!!#
    
    * module/ice-9/read.scm (%read): Fix reading #!!#.
    * test-suite/tests/reader.test ("reading"): Add some test cases.
---
 module/ice-9/read.scm        | 18 ++++++++++--------
 test-suite/tests/reader.test | 17 ++++++++++++++++-
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/module/ice-9/read.scm b/module/ice-9/read.scm
index 17215d8..a8dbd92 100644
--- a/module/ice-9/read.scm
+++ b/module/ice-9/read.scm
@@ -731,16 +731,18 @@
                     (read-neoteric ch)))))
 
   (define (read-directive)
-    (let ((ch (next)))
+    (define (directive-char? ch)
+      (and (char? ch)
+           (or (eqv? ch #\-)
+               (char-alphabetic? ch)
+               (char-numeric? ch))))
+    (let ((ch (peek)))
       (cond
-       ((eof-object? ch)
-        (error "unexpected end of input after #!"))
+       ((directive-char? ch)
+        (next)
+        (string->symbol (take-while ch directive-char?)))
        (else
-        (string->symbol
-         (take-while ch (lambda (ch)
-                          (or (eqv? ch #\-)
-                              (char-alphabetic? ch)
-                              (char-numeric? ch)))))))))
+        #f))))
 
   (define (skip-scsh-comment)
     (let lp ((ch (next)))
diff --git a/test-suite/tests/reader.test b/test-suite/tests/reader.test
index 535ff1c..fad531b 100644
--- a/test-suite/tests/reader.test
+++ b/test-suite/tests/reader.test
@@ -184,7 +184,22 @@
                      (read-string "'(foo bar]"))
 
   (pass-if-exception "paren mismatch (4)" exception:mismatched-paren
-                     (read-string "'[foo bar)")))
+    (read-string "'[foo bar)"))
+
+  (pass-if-equal '(#f 1) (read-string "(#f1)"))
+  (pass-if-equal '(#f a) (read-string "(#fa)"))
+  (pass-if-equal '(#f a) (read-string "(#Fa)"))
+  (pass-if-equal '(#t 1) (read-string "(#t1)"))
+  (pass-if-equal '(#t r) (read-string "(#tr)"))
+  (pass-if-equal '(#t r) (read-string "(#Tr)"))
+  (pass-if-equal '(#t) (read-string "(#TrUe)"))
+  (pass-if-equal '(#t) (read-string "(#TRUE)"))
+  (pass-if-equal '(#t) (read-string "(#true)"))
+  (pass-if-equal '(#f) (read-string "(#false)"))
+  (pass-if-equal '(#f) (read-string "(#FALSE)"))
+  (pass-if-equal '(#f) (read-string "(#FaLsE)"))
+
+  (pass-if (eof-object? (read-string "#!!#"))))
 
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]