annotate tests/automated/lisp-reader-tests.el @ 5908:6174848f3e6c

Use parse_integer() in read_atom(); support bases with ratios like integers src/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * data.c (init_errors_once_early): Move the Qunsupported_type here from numbers.c, so it's available when the majority of our types are not supported. * general-slots.h: Add it here, too. * number.c: Remove the definition of Qunsupported_type from here. * lread.c (read_atom): Check if the first character could reflect a rational, if so, call parse_integer(), don't check the syntax of the other characters. This allows us to accept the non-ASCII digit characters too. If that worked partially, but not completely, and the next char is a slash, try to parse as a ratio. If that fails, try isfloat_string(), but only if the first character could plausibly be part of a float. Otherwise, treat as a symbol. * lread.c (read_rational): Rename from read_integer. Handle ratios with the same radix specification as was used for integers. * lread.c (read1): Rename read_integer in this function. Support the Common Lisp #NNNrMMM syntax for parsing a number MMM of arbitrary radix NNN. man/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * lispref/numbers.texi (Numbers): Describe the newly-supported arbitrary-base syntax for rationals (integers and ratios). Describe that ratios can take the same base specification as integers, something also new. tests/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-reader-tests.el: Check the arbitrary-base integer reader syntax support, just added. Check the reader base support for ratios, just added. Check the non-ASCII-digit support in the reader, just added.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 09 May 2015 00:40:57 +0100
parents ee27ca517e90
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3543
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
1 ;; Copyright (C) 2005 Martin Kuehl.
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
2
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
3 ;; Author: Martin Kuehl <martin.kuehl@gmail.com>
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
4 ;; Maintainer: Martin Kuehl <martin.kuehl@gmail.com>
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
5 ;; Created: 2005
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
6 ;; Keywords: tests
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
7
5290
e6508b64ee08 More permission consistency.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 3543
diff changeset
8 ;; This file is part of XEmacs.
3543
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
9
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3543
diff changeset
10 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3543
diff changeset
11 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3543
diff changeset
12 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3543
diff changeset
13 ;; option) any later version.
3543
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
14
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3543
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3543
diff changeset
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3543
diff changeset
17 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3543
diff changeset
18 ;; for more details.
3543
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
19
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3543
diff changeset
21 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
3543
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
22
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
23 ;;; Synched up with: Not in FSF.
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
24
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
25 ;;; Commentary:
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
26
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
27 ;; Test the lisp reader.
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
28 ;; See test-harness.el for instructions on how to run these tests.
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
29
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
30 ;;; Raw Strings
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
31 ;;; ===========
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
32
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
33 ;; Equality to "traditional" strings
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
34 ;; ---------------------------------
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
35 (dolist (strings '((#r"xyz" "xyz") ; no backslashes
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
36 (#r"\xyz" "\\xyz") ; backslash at start
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
37 (#r"\\xyz" "\\\\xyz") ; backslashes at start
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
38 (#r"\nxyz" "\\nxyz") ; escape seq. at start
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
39 (#r"\"xyz" "\\\"xyz") ; quote at start
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
40 (#r"xy\z" "xy\\z") ; backslash in middle
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
41 (#r"xy\\z" "xy\\\\z") ; backslashes in middle
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
42 (#r"xy\nz" "xy\\nz") ; escape seq. in middle
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
43 (#r"xy\"z" "xy\\\"z") ; quote in middle
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
44 ;;(#r"xyz\" "xyz\\") ; backslash at end: error
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
45 (#r"xyz\\" "xyz\\\\") ; backslashes at end
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
46 (#r"xyz\n" "xyz\\n") ; escape seq. at end
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
47 (#r"xyz\"" "xyz\\\"") ; quote at end
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
48 (#ru"\u00ABxyz" "\u00ABxyz") ; one Unicode escape
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
49 (#rU"\U000000ABxyz" "\U000000ABxyz") ; another Unicode escape
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
50 (#rU"xyz\u00AB" "xyz\u00AB") ; one Unicode escape
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
51 ))
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
52 (Assert (apply #'string= strings)))
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
53
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
54 ;; Odd number of backslashes at the end
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
55 ;; ------------------------------------
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
56 (dolist (string '("#r\"xyz\\\"" ; `#r"abc\"': escaped delimiter
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
57 "#r\"xyz\\\\\\\"" ; `#r"abc\\\"': escaped delimiter
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
58 ))
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
59 (with-temp-buffer
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
60 (insert string)
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
61 (Check-Error end-of-file (eval-buffer))))
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
62
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
63 ;; Alternate string/regex delimiters
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
64 ;; ---------------------------------
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
65 (dolist (string '("#r/xyz/" ; Perl syntax
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
66 "#r:ix/xyz/" ; Extended Perl syntax
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
67 "#r|xyz|" ; TeX syntax
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
68 "#r[xyz]" ; (uncommon) Perl syntax
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
69 "#r<xyz>" ; Perl6 syntax?
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
70 "#r(xyz)" ; arbitrary santax
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
71 "#r{xyz}" ; arbitrary santax
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
72 "#r,xyz," ; arbitrary santax
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
73 "#r!xyz!" ; arbitrary santax
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
74 ))
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
75 (with-temp-buffer
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
76 (insert string)
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
77 (Check-Error-Message invalid-read-syntax "unrecognized raw string"
c136144fe765 [xemacs-hg @ 2006-08-04 22:55:04 by aidan]
aidan
parents:
diff changeset
78 (eval-buffer))))
5489
159face738c3 Never pass a leading + to mpz_set_string, parse_integer ().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5420
diff changeset
79
159face738c3 Never pass a leading + to mpz_set_string, parse_integer ().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5420
diff changeset
80 (when (featurep 'bignum)
159face738c3 Never pass a leading + to mpz_set_string, parse_integer ().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5420
diff changeset
81 ;; This failed, up to 20110501.
159face738c3 Never pass a leading + to mpz_set_string, parse_integer ().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5420
diff changeset
82 (Assert (eql (1+ most-positive-fixnum)
159face738c3 Never pass a leading + to mpz_set_string, parse_integer ().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5420
diff changeset
83 (read (format "+%d" (1+ most-positive-fixnum))))
159face738c3 Never pass a leading + to mpz_set_string, parse_integer ().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5420
diff changeset
84 "checking leading + is handled properly if reading a bignum")
159face738c3 Never pass a leading + to mpz_set_string, parse_integer ().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5420
diff changeset
85 ;; This never did.
159face738c3 Never pass a leading + to mpz_set_string, parse_integer ().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5420
diff changeset
86 (Assert (eql (1- most-positive-fixnum)
159face738c3 Never pass a leading + to mpz_set_string, parse_integer ().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5420
diff changeset
87 (read (format "+%d" (1- most-positive-fixnum))))
159face738c3 Never pass a leading + to mpz_set_string, parse_integer ().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5420
diff changeset
88 "checking leading + is handled properly if reading a fixnum"))
159face738c3 Never pass a leading + to mpz_set_string, parse_integer ().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5420
diff changeset
89
5560
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
90 ;; Test print-circle.
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
91 (let ((cons '#1=(1 2 3 4 5 6 . #1#))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
92 (vector #2=[1 2 3 4 5 6 #2#])
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
93 (compiled-function #3=#[(argument) "\xc2\x09\x08\"\x87"
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
94 [pi argument #3#] 3])
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
95 (char-table #4=#s(char-table :type generic :data (?\u0080 #4#)))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
96 (hash-table #5=#s(hash-table :test eql :data (a b c #5# e f)))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
97 (range-table #6=#s(range-table :type start-closed-end-open
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
98 :data ((#x00 #xff) hello
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
99 (#x100 #x1ff) #6#
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
100 (#x200 #x2ff) everyone)))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
101 (print-readably t)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
102 (print-circle t)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
103 deserialized-cons deserialized-vector deserialized-compiled-function
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
104 deserialized-char-table deserialized-hash-table deserialized-range-table)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
105 (Assert (eq (nthcdr 6 cons) cons)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
106 "checking basic recursive cons read properly")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
107 (Assert (eq vector (aref vector (1- (length vector))))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
108 "checking basic recursive vector read properly")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
109 (Assert (eq compiled-function
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
110 (find-if #'compiled-function-p
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
111 (compiled-function-constants compiled-function)))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
112 "checking basic recursive compiled-function read properly")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
113 (Check-Error wrong-number-of-arguments (funcall compiled-function 3))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
114 (Assert (eq char-table (get-char-table ?\u0080 char-table))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
115 "checking basic recursive char table read properly")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
116 (Assert (eq hash-table (gethash 'c hash-table))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
117 "checking basic recursive hash table read properly")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
118 (Assert (eq range-table (get-range-table #x180 range-table))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
119 "checking basic recursive range table read properly")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
120 (setf (gethash 'g hash-table) cons
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
121 (car cons) hash-table
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
122 deserialized-hash-table (read (prin1-to-string hash-table)))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
123 (Assert (not (eq deserialized-hash-table hash-table))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
124 "checking printing and reading hash-table creates a new object")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
125 (Assert (eq deserialized-hash-table (gethash 'c deserialized-hash-table))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
126 "checking the lisp reader handles deserialized hash-table identity")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
127 (Assert (eq deserialized-hash-table
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
128 (car (gethash 'g deserialized-hash-table)))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
129 "checking the reader handles deserialization identity, hash-table")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
130 (setf (get-char-table ?a char-table) cons
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
131 (car cons) char-table
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
132 deserialized-char-table (read (prin1-to-string char-table)))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
133 (Assert (not (eq deserialized-char-table char-table))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
134 "checking printing and reading creates a new object")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
135 (Assert (eq deserialized-char-table
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
136 (get-char-table ?\u0080 deserialized-char-table))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
137 "checking the lisp reader handles deserialization identity")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
138 (Assert (eq deserialized-char-table
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
139 (car (get-char-table ?a deserialized-char-table)))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
140 "checking the lisp reader handles deserialization identity, mixed")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
141 (put-range-table #x1000 #x1010 cons range-table)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
142 (setf (car cons) range-table
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
143 deserialized-range-table (read (prin1-to-string range-table)))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
144 (Assert (not (eq deserialized-range-table range-table))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
145 "checking printing and reading creates a new object")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
146 (Assert (eq deserialized-range-table
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
147 (get-range-table #x101 deserialized-range-table))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
148 "checking the lisp reader handles deserialization identity")
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
149 (Assert (eq deserialized-range-table
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
150 (car (get-range-table #x1001 deserialized-range-table)))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
151 "checking the lisp reader handles deserialization identity, mixed"))
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5489
diff changeset
152
5605
cc7f8a0e569a Accept bignums unambiguously in the syntax for object labels, lread.c.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5560
diff changeset
153 (when (featurep 'bignum)
cc7f8a0e569a Accept bignums unambiguously in the syntax for object labels, lread.c.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5560
diff changeset
154 (Assert (null (list-length (read (format "#%d=(1 #1=(5) 3 4 . #%d#)"
cc7f8a0e569a Accept bignums unambiguously in the syntax for object labels, lread.c.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5560
diff changeset
155 (+ most-positive-fixnum 2)
cc7f8a0e569a Accept bignums unambiguously in the syntax for object labels, lread.c.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5560
diff changeset
156 (+ most-positive-fixnum 2)))))
cc7f8a0e569a Accept bignums unambiguously in the syntax for object labels, lread.c.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5560
diff changeset
157 "checking bignum object labels don't wrap on reading"))
5904
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
158
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
159 (Assert (not (eq (intern "") (read (prin1-to-string (make-symbol "")))))
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
160 "checking uninterned zero-length symbol printed distinctly")
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
161
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
162 ;; Check the read and print handling of symbols that look like numbers. In
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
163 ;; passing, check the read and print handling of the associated numbers.
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
164 (Assert (eql (log 1) '0e0) "checking float syntax with e accepted")
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
165 (Assert (eql (log 1) 0.0) "checking float syntax with decimal point accepted")
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
166 (Assert (not (ratiop (read "2/-3")))
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
167 "ratios can't have a negative sign in the denominator")
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
168 (Assert (not (ratiop (read "2/+3")))
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
169 "ratios can't have a positive sign in the denominator")
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
170
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
171 (macrolet
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
172 ((Assert-no-symbol-number-confusion (&rest values)
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
173 `(let ((print-gensym t)
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
174 (print-readably t))
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
175 ,@(loop
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
176 for (type . rest) in values
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
177 collect (cons
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
178 'progn
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
179 (loop for string in rest
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
180 collect
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
181 `(progn
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
182 (Assert (symbolp (read (prin1-to-string
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
183 (make-symbol ,string)))))
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
184 (Assert (equal (symbol-name
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
185 (read (prin1-to-string
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
186 (make-symbol ,string))))
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
187 ,string))
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
188 ,@(when (ignore-errors (coerce-number 1 type))
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
189 `((Assert (typep (read ,string)
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
190 ',type))
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
191 (Assert (eql (string-to-number
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
192 ,string)
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
193 (read ,string))))))))))))
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
194 (Assert-no-symbol-number-confusion
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
195 (float "0.0" "0E0" "-.0" "0.0e0" "3.1415926535897932384E0"
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
196 "6.02E+23" "602E+21" "3.010299957e-1" "-0.000000001e9")
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
197 (fixnum "1" "1." "1073741823" "-1" "-1073741824")
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
198 (ratio "1/2" "2/5" "-1073741822/1073741823"
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
199 "+2/3" "-3/2"
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
200 "2894802230932904885589274625217197696331749616641014100986439600\
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
201 1978282409984/20"
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
202 "+289480223093290488558927462521719769633174961664101410098643960\
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
203 01978282409984/20"
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
204 "-289480223093290488558927462521719769633174961664101410098643960\
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
205 01978282409984/20"
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
206 "20/2894802230932904885589274625217197696331749616641014100986439\
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
207 6001978282409984"
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
208 "+20/289480223093290488558927462521719769633174961664101410098643\
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
209 96001978282409984"
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
210 "-20/289480223093290488558927462521719769633174961664101410098643\
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
211 96001978282409984")
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
212 ;; These two are (lsh 1 254) and (lognot (lsh 1 254)). The assumption that
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
213 ;; they are always bignums if they can be made into rationals should hold
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
214 ;; for another couple of processor generations at least.
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
215 (bignum
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
216 "2894802230932904885589274625217197696331749616641014100986439600197828\
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
217 2409984"
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
218 "-289480223093290488558927462521719769633174961664101410098643960019782\
ee27ca517e90 Revise print_symbol(), never calling is{float,ratio}_string().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5605
diff changeset
219 82409985")))
5908
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
220
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
221 (macrolet
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
222 ((Assert-reading-rationals (&rest details)
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
223 (cons
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
224 'progn
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
225 (loop
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
226 for (guard first . rest) in details
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
227 collect `(when ,guard
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
228 ,@(loop for value in rest
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
229 collect `(Assert (eql ,first
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
230 (read ,value))))))))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
231 (with-digits (ascii alternate &body body)
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
232 (let ((tree-alist (list (cons 'old 'new)))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
233 (text-alist (mapcar* #'cons ascii alternate)))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
234 (list*
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
235 'progn
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
236 (sublis tree-alist body
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
237 :test #'(lambda (new old)
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
238 ;; This function replaces any ASCII decimal digits
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
239 ;; in any string encountered in the tree with the
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
240 ;; non-ASCII digits supplied in ALTERNATE.
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
241 (when (and (stringp old)
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
242 (find-if #'digit-char-p old))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
243 (setf (cdar tree-alist)
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
244 (concatenate 'string
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
245 (sublis text-alist
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
246 (append old nil))))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
247 t))))))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
248 (with-all-digits (&body body)
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
249 (list
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
250 'progn
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
251 (list* 'with-digits "0123456789" "0123456789" body)
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
252 (when (featurep 'mule)
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
253 (cons
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
254 'progn
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
255 (loop for (code-point . script)
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
256 in '((#x0660 . "Arabic-Indic")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
257 (#x06f0 . "Extended Arabic-Indic")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
258 (#x07c0 . "Nko")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
259 (#x0966 . "Devanagari")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
260 (#x09e6 . "Bengali")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
261 (#x0a66 . "Gurmukhi")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
262 (#x0ae6 . "Gujarati")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
263 (#x0b66 . "Oriya")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
264 (#x0be6 . "Tamil")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
265 (#x0c66 . "Telugu")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
266 (#x0ce6 . "Kannada")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
267 (#x0d66 . "Malayalam")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
268 (#x0de6 . "Sinhala Lith")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
269 (#x0e50 . "Thai")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
270 (#x0ed0 . "Lao")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
271 (#x0f20 . "Tibetan")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
272 (#x1040 . "Myanmar")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
273 (#x1090 . "Myanmar Shan")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
274 (#x17e0 . "Khmer")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
275 (#x1810 . "Mongolian")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
276 (#x1946 . "Limbu")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
277 (#x19d0 . "New Tai Lue")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
278 (#x1a80 . "Tai Tham Hora")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
279 (#x1a90 . "Tai Tham Tham")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
280 (#x1b50 . "Balinese")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
281 (#x1bb0 . "Sundanese")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
282 (#x1c40 . "Lepcha")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
283 (#x1c50 . "Ol Chiki")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
284 (#xa620 . "Vai")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
285 (#xa8d0 . "Saurashtra")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
286 (#xa900 . "Kayah Li")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
287 (#xa9d0 . "Javanese")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
288 (#xa9f0 . "Myanmar Tai Laing")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
289 (#xaa50 . "Cham")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
290 (#xabf0 . "Meetei Mayek")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
291 (#xff10 . "Fullwidth")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
292 (#x000104a0 . "Osmanya")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
293 (#x00011066 . "Brahmi")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
294 (#x000110f0 . "Sora Sompeng")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
295 (#x00011136 . "Chakma")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
296 (#x000111d0 . "Sharada")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
297 (#x000112f0 . "Khudawadi")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
298 (#x000114d0 . "Tirhuta")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
299 (#x00011650 . "Modi")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
300 (#x000116c0 . "Takri")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
301 (#x000118e0 . "Warang Citi")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
302 (#x00016a60 . "Mro")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
303 (#x00016b50 . "Pahawh Hmong")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
304 (#x0001d7ce . "Mathematical Bold")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
305 (#x0001d7d8 . "Mathematical Double-Struck")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
306 (#x0001d7e2 . "Mathematical Sans-Serif")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
307 (#x0001d7ec . "Mathematical Sans-Serif Bold")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
308 (#x0001d7f6 . "Mathematical Monospace"))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
309 collect
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
310 (list* 'with-digits "0123456789"
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
311 ;; All the Unicode decimal digits have contiguous code
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
312 ;; point ranges as documented by the Unicode standard,
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
313 ;; we can just increment.
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
314 (concat (loop for fixnum from code-point
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
315 to (+ code-point 9)
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
316 collect (decode-char 'ucs fixnum))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
317 "")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
318 body)))))))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
319 (with-all-digits
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
320 (Assert-reading-rationals
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
321 (t 1 "1" "#b1" "#o1" "#x1" "#2r1" "#20r1" "#2000r1")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
322 (t 0 "-0" "#b0" "#o0" "#x0" "#1r0" "#2r0" "#20r0" "#2000r0")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
323 (t -1 "-1" "#b-1" "#o-1" "#x-1" "#2r-1" "#20r-1" "#2000r-1")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
324 (t 1073741823 "#b111111111111111111111111111111" "#o7777777777"
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
325 "#x3fffffff" "#32rVVVVVV")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
326 (t -1073741824 "#b-1000000000000000000000000000000" "#o-10000000000"
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
327 "#x-40000000" "#32r-1000000")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
328 ((featurep 'ratio)
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
329 1 "1/1" "2/2" "#b1/1" "#o2/2" "#x3/3" "#2r1/1" "#20r2000/2000")
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
330 ((featurep 'ratio)
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
331 -1 "-1/1" "-2/2" "#b-1/1" "#o-2/2" "#x-3/3" "#2r-1/1"
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
332 "#20r-2000/2000"))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
333 (Check-Error invalid-read-syntax (read "1234567/0"))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
334 (Check-Error invalid-read-syntax (read "#x1234567/0"))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
335 (Check-Error invalid-read-syntax (read "#20000r1234567/0"))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
336 ;; Unintuitive, but that's the Common Lisp behaviour. Maybe we should
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
337 ;; error.
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
338 (Assert (symbolp (read "1234/-123")))))
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
339
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5904
diff changeset
340 ;;; end of lisp-reader-tests.el