unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andreas Rottmann <a.rottmann@gmx.at>
To: guile-devel@gnu.org
Subject: [PATCH] Make `get-datum' conform more closely to R6RS semantics
Date: Mon,  5 Nov 2012 00:59:04 +0100	[thread overview]
Message-ID: <1352073544-24166-1-git-send-email-a.rottmann@gmx.at> (raw)

* module/rnrs/io/ports.scm (get-datum): Set reader options to be more
  compatible with R6RS syntax.

  With Guile's default reader options, R6RS hex escape and EOL escape
  behavior is missing.  This change enables the former via the
  `r6rs-hex-escapes' option, and gets us closer to the latter by setting
  `hungry-eol-escapes'.

* test-suite/tests/r6rs-ports.test ("8.2.9 Textual input")["get-datum"]:
  New tests.
---
 module/rnrs/io/ports.scm         |   13 +++++++++++--
 test-suite/tests/r6rs-ports.test |   28 ++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/module/rnrs/io/ports.scm b/module/rnrs/io/ports.scm
index fddb491..6e6a66d 100644
--- a/module/rnrs/io/ports.scm
+++ b/module/rnrs/io/ports.scm
@@ -1,6 +1,6 @@
 ;;;; ports.scm --- R6RS port API                    -*- coding: utf-8 -*-
 
-;;;;	Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
+;;;;	Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
 ;;;; modify it under the terms of the GNU Lesser General Public
@@ -437,7 +437,16 @@ return the characters accumulated in that port."
   (with-textual-input-conditions port (read-char port)))
 
 (define (get-datum port)
-  (with-textual-input-conditions port (read port)))
+  (with-textual-input-conditions port
+    (let ((saved-options (read-options)))
+      (dynamic-wind
+        (lambda () (read-options '(positions
+                                   keywords #f
+                                   square-brackets
+                                   r6rs-hex-escapes
+                                   hungry-eol-escapes)))
+        (lambda () (read port))
+        (lambda () (read-options saved-options))))))
 
 (define (get-line port)
   (with-textual-input-conditions port (read-line port 'trim)))
diff --git a/test-suite/tests/r6rs-ports.test b/test-suite/tests/r6rs-ports.test
index 46da67f..6a7386e 100644
--- a/test-suite/tests/r6rs-ports.test
+++ b/test-suite/tests/r6rs-ports.test
@@ -719,6 +719,34 @@
       (and (= 3 (get-string-n! port s 6 3))
            (string=? s "Isn't GNU great?"))))
 
+  (with-test-prefix "get-datum"
+    (let ((string->datum (lambda (s) (get-datum (open-input-string s)))))
+      (pass-if "symbol"
+        (eq? (string->datum "foo") 'foo))
+      (pass-if "symbol [starting with colon]"
+        (eq? ':foo (string->datum ":foo")))
+      (pass-if "string"
+        (string=? "foo" (string->datum "\"foo\"")))
+      (pass-if "string [with hex escapes]"
+        (string=? "bar\nA" (string->datum "\"bar\\x0A;\\x41;\"")))
+      (pass-if "string [hungry EOL]"
+        (string=? "bar baz" (string->datum "\"bar \\\n   baz\"")))
+      ;; FIXME: actually, R6RS demands an even more hungry EOL escape
+      ;; than the reader currently implements: also any whitespace
+      ;; between the backslash and the newline should vanish. Currently,
+      ;; the reader barfs on that.
+      (pass-if "string [hungry EOL, space also before newline]"
+        (throw 'unresolved)
+        (string=? "bar baz" (string->datum "\"bar \\  \n   baz\"")))
+      (pass-if "number [decimal]"
+        (= (string->datum "42") 42))
+      (pass-if "number [hexadecimal]"
+        (= (string->datum "#x2A") 42))
+      (pass-if "number [octal]"
+        (= (string->datum "#o0777") 511))
+      (pass-if "number [binary]"
+        (= (string->datum "#b101010") 42))))
+
   (with-test-prefix "read error"
     (pass-if-condition "get-char" i/o-read-error?
       (get-char (make-failing-port)))
-- 
1.7.10.4




             reply	other threads:[~2012-11-04 23:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-04 23:59 Andreas Rottmann [this message]
2012-11-05  5:07 ` [PATCH] Make `get-datum' conform more closely to R6RS semantics Mark H Weaver
2012-11-05 17:52   ` Ludovic Courtès
2012-11-06  7:36     ` Improving the API for read options Mark H Weaver
2012-11-06 19:01       ` Ludovic Courtès
2012-11-11  7:56         ` Mark H Weaver
2012-11-06 19:55   ` [PATCH] Make `get-datum' conform more closely to R6RS semantics Andreas Rottmann

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=1352073544-24166-1-git-send-email-a.rottmann@gmx.at \
    --to=a.rottmann@gmx.at \
    --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).