From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Rottmann Newsgroups: gmane.lisp.guile.devel Subject: [PATCH] Make `get-datum' conform more closely to R6RS semantics Date: Mon, 5 Nov 2012 00:59:04 +0100 Message-ID: <1352073544-24166-1-git-send-email-a.rottmann@gmx.at> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1352073563 5480 80.91.229.3 (4 Nov 2012 23:59:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 4 Nov 2012 23:59:23 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Nov 05 00:59:32 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TVA6G-0004cp-Bh for guile-devel@m.gmane.org; Mon, 05 Nov 2012 00:59:32 +0100 Original-Received: from localhost ([::1]:60594 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TVA67-0002Xi-Gs for guile-devel@m.gmane.org; Sun, 04 Nov 2012 18:59:23 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:37368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TVA64-0002XS-Uq for guile-devel@gnu.org; Sun, 04 Nov 2012 18:59:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TVA63-0007IC-Nm for guile-devel@gnu.org; Sun, 04 Nov 2012 18:59:20 -0500 Original-Received: from mailout-de.gmx.net ([213.165.64.23]:39665) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1TVA63-0007I7-ED for guile-devel@gnu.org; Sun, 04 Nov 2012 18:59:19 -0500 Original-Received: (qmail invoked by alias); 04 Nov 2012 23:59:17 -0000 Original-Received: from 91-119-183-25.dynamic.xdsl-line.inode.at (EHLO cubox.home.rotty.xx.vu) [91.119.183.25] by mail.gmx.net (mp027) with SMTP; 05 Nov 2012 00:59:17 +0100 X-Authenticated: #3102804 X-Provags-ID: V01U2FsdGVkX19DiRl3+IRDrZ2QhSd/eB+cIz6SneHWidF6T+2vEb BKyKgq6dHAmkFy Original-Received: from delenn.lan (delenn.home.rotty.xx.vu [IPv6:fdfb:599d:f328:2::6e]) by cubox.home.rotty.xx.vu (Postfix) with ESMTP id 445C216009E; Mon, 5 Nov 2012 00:59:13 +0100 (CET) Original-Received: by delenn.lan (Postfix, from userid 1000) id 189CC320141; Mon, 5 Nov 2012 00:59:13 +0100 (CET) X-Mailer: git-send-email 1.7.10.4 X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 213.165.64.23 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:15086 Archived-At: * 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