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 3/3] Make `get-datum' conform more closely to R6RS semantics Date: Sun, 9 Dec 2012 13:47:27 +0100 Message-ID: <1355057247-17885-4-git-send-email-a.rottmann@gmx.at> References: <1355057247-17885-1-git-send-email-a.rottmann@gmx.at> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1355057284 17290 80.91.229.3 (9 Dec 2012 12:48:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Dec 2012 12:48:04 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Dec 09 13:48:17 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 1ThgIq-0000ST-4S for guile-devel@m.gmane.org; Sun, 09 Dec 2012 13:48:16 +0100 Original-Received: from localhost ([::1]:49094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ThgId-0002v4-Oi for guile-devel@m.gmane.org; Sun, 09 Dec 2012 07:48:03 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:42070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ThgIa-0002tD-Hq for guile-devel@gnu.org; Sun, 09 Dec 2012 07:48:02 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ThgIY-0008Cy-Bp for guile-devel@gnu.org; Sun, 09 Dec 2012 07:48:00 -0500 Original-Received: from mailout-de.gmx.net ([213.165.64.22]:53357) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1ThgIY-0008Cm-20 for guile-devel@gnu.org; Sun, 09 Dec 2012 07:47:58 -0500 Original-Received: (qmail invoked by alias); 09 Dec 2012 12:47:57 -0000 Original-Received: from 91-119-183-136.dynamic.xdsl-line.inode.at (EHLO cubox.home.rotty.xx.vu) [91.119.183.136] by mail.gmx.net (mp028) with SMTP; 09 Dec 2012 13:47:57 +0100 X-Authenticated: #3102804 X-Provags-ID: V01U2FsdGVkX189ty4vQHQ9O/kdvX5mYd17mY01E9LyuxSnDinTU/ /cA1OdiXlL6x21 Original-Received: from delenn.home.rotty.xx.vu (delenn.home.rotty.xx.vu [IPv6:fdfb:599d:f328:2::6e]) by cubox.home.rotty.xx.vu (Postfix) with ESMTP id 84B9316009E; Sun, 9 Dec 2012 13:47:55 +0100 (CET) Original-Received: by delenn.home.rotty.xx.vu (Postfix, from userid 1000) id 7C9E4320160; Sun, 9 Dec 2012 13:47:55 +0100 (CET) X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1355057247-17885-1-git-send-email-a.rottmann@gmx.at> X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 213.165.64.22 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:15320 Archived-At: 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'. * libguile/r6rs-ports.c (R6RS_READ_OPTION_MASK): New macro, defines which reader options need fixed values according to R6RS. (r6rs_read_options): New internal constant, defining the values of the relevant reader options. (scm_i_get_datum): New internal helper calling `scm_i_read' using the R6RS reader options. * module/rnrs/io/ports.scm (get-datum): Call `%get-datum' instead of `read'. * test-suite/tests/r6rs-ports.test ("8.2.9 Textual input")["get-datum"]: New tests. --- libguile/r6rs-ports.c | 29 ++++++++++++++++++++++++ module/rnrs/io/ports.scm | 2 +- test-suite/tests/r6rs-ports.test | 45 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/libguile/r6rs-ports.c b/libguile/r6rs-ports.c index 19dea8d..973953a 100644 --- a/libguile/r6rs-ports.c +++ b/libguile/r6rs-ports.c @@ -174,6 +174,35 @@ SCM_DEFINE (scm_i_make_transcoded_port, } #undef FUNC_NAME +#define R6RS_READ_OPTION_MASK \ + ((1 << SCM_READ_OPTION_KEYWORD_STYLE) \ + | (1 << SCM_READ_OPTION_R6RS_ESCAPES_P) \ + | (1 << SCM_READ_OPTION_CASE_INSENSITIVE_P) \ + | (1 << SCM_READ_OPTION_SQUARE_BRACKETS_P) \ + | (1 << SCM_READ_OPTION_HUNGRY_EOL_ESCAPES_P)) + +static const scm_t_read_opts r6rs_read_options = { + SCM_KEYWORD_STYLE_HASH_PREFIX, + 0, /* copy_source_p, not relevant */ + 0, /* record_positions_p, not relevant */ + 0, /* case_insensitive_p */ + 1, /* r6rs_escapes_p */ + 1, /* square_brackets_p */ + 1, /* hungry_eol_escapes_p */ + 0, /* curly_infix_p, compatible extension */ + 0, /* neoteric_p, not relevant */ +}; + +SCM_DEFINE (scm_i_get_datum, + "%get-datum", 1, 0, 0, + (SCM port), + "Read a datum in R6RS syntax from @var{port}") +#define FUNC_NAME s_scm_i_get_datum +{ + return scm_i_read(port, &r6rs_read_options, R6RS_READ_OPTION_MASK); +} +#undef FUNC_NAME + /* Initialization. */ diff --git a/module/rnrs/io/ports.scm b/module/rnrs/io/ports.scm index ee8c05a..b2828cd 100644 --- a/module/rnrs/io/ports.scm +++ b/module/rnrs/io/ports.scm @@ -458,7 +458,7 @@ 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 (%get-datum port))) (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 ed49598..6a92987 100644 --- a/test-suite/tests/r6rs-ports.test +++ b/test-suite/tests/r6rs-ports.test @@ -707,6 +707,16 @@ (eq? (error-handling-mode replace) (transcoder-error-handling-mode t)))))) +;; FIXME: duplicated from reader.test +(define (with-read-options opts thunk) + (let ((saved-options (read-options))) + (dynamic-wind + (lambda () + (read-options opts)) + thunk + (lambda () + (read-options saved-options))))) + (with-test-prefix "8.2.9 Textual input" (pass-if "get-string-n [short]" @@ -724,6 +734,41 @@ (s (string-copy "Isn't XXX great?"))) (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) + ;; We should check against all possible permutations of + ;; read options, but we just enable (and leave disabled) + ;; the ones that each would break R6RS individually. + (with-read-options '(keywords prefix case-insensitive hungry-eol-escapes) + (lambda () (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 "symbol ending 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? -- 1.7.10.4