comparison 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
comparison
equal deleted inserted replaced
5907:87e29d93e11b 5908:6174848f3e6c
215 (bignum 215 (bignum
216 "2894802230932904885589274625217197696331749616641014100986439600197828\ 216 "2894802230932904885589274625217197696331749616641014100986439600197828\
217 2409984" 217 2409984"
218 "-289480223093290488558927462521719769633174961664101410098643960019782\ 218 "-289480223093290488558927462521719769633174961664101410098643960019782\
219 82409985"))) 219 82409985")))
220
221 (macrolet
222 ((Assert-reading-rationals (&rest details)
223 (cons
224 'progn
225 (loop
226 for (guard first . rest) in details
227 collect `(when ,guard
228 ,@(loop for value in rest
229 collect `(Assert (eql ,first
230 (read ,value))))))))
231 (with-digits (ascii alternate &body body)
232 (let ((tree-alist (list (cons 'old 'new)))
233 (text-alist (mapcar* #'cons ascii alternate)))
234 (list*
235 'progn
236 (sublis tree-alist body
237 :test #'(lambda (new old)
238 ;; This function replaces any ASCII decimal digits
239 ;; in any string encountered in the tree with the
240 ;; non-ASCII digits supplied in ALTERNATE.
241 (when (and (stringp old)
242 (find-if #'digit-char-p old))
243 (setf (cdar tree-alist)
244 (concatenate 'string
245 (sublis text-alist
246 (append old nil))))
247 t))))))
248 (with-all-digits (&body body)
249 (list
250 'progn
251 (list* 'with-digits "0123456789" "0123456789" body)
252 (when (featurep 'mule)
253 (cons
254 'progn
255 (loop for (code-point . script)
256 in '((#x0660 . "Arabic-Indic")
257 (#x06f0 . "Extended Arabic-Indic")
258 (#x07c0 . "Nko")
259 (#x0966 . "Devanagari")
260 (#x09e6 . "Bengali")
261 (#x0a66 . "Gurmukhi")
262 (#x0ae6 . "Gujarati")
263 (#x0b66 . "Oriya")
264 (#x0be6 . "Tamil")
265 (#x0c66 . "Telugu")
266 (#x0ce6 . "Kannada")
267 (#x0d66 . "Malayalam")
268 (#x0de6 . "Sinhala Lith")
269 (#x0e50 . "Thai")
270 (#x0ed0 . "Lao")
271 (#x0f20 . "Tibetan")
272 (#x1040 . "Myanmar")
273 (#x1090 . "Myanmar Shan")
274 (#x17e0 . "Khmer")
275 (#x1810 . "Mongolian")
276 (#x1946 . "Limbu")
277 (#x19d0 . "New Tai Lue")
278 (#x1a80 . "Tai Tham Hora")
279 (#x1a90 . "Tai Tham Tham")
280 (#x1b50 . "Balinese")
281 (#x1bb0 . "Sundanese")
282 (#x1c40 . "Lepcha")
283 (#x1c50 . "Ol Chiki")
284 (#xa620 . "Vai")
285 (#xa8d0 . "Saurashtra")
286 (#xa900 . "Kayah Li")
287 (#xa9d0 . "Javanese")
288 (#xa9f0 . "Myanmar Tai Laing")
289 (#xaa50 . "Cham")
290 (#xabf0 . "Meetei Mayek")
291 (#xff10 . "Fullwidth")
292 (#x000104a0 . "Osmanya")
293 (#x00011066 . "Brahmi")
294 (#x000110f0 . "Sora Sompeng")
295 (#x00011136 . "Chakma")
296 (#x000111d0 . "Sharada")
297 (#x000112f0 . "Khudawadi")
298 (#x000114d0 . "Tirhuta")
299 (#x00011650 . "Modi")
300 (#x000116c0 . "Takri")
301 (#x000118e0 . "Warang Citi")
302 (#x00016a60 . "Mro")
303 (#x00016b50 . "Pahawh Hmong")
304 (#x0001d7ce . "Mathematical Bold")
305 (#x0001d7d8 . "Mathematical Double-Struck")
306 (#x0001d7e2 . "Mathematical Sans-Serif")
307 (#x0001d7ec . "Mathematical Sans-Serif Bold")
308 (#x0001d7f6 . "Mathematical Monospace"))
309 collect
310 (list* 'with-digits "0123456789"
311 ;; All the Unicode decimal digits have contiguous code
312 ;; point ranges as documented by the Unicode standard,
313 ;; we can just increment.
314 (concat (loop for fixnum from code-point
315 to (+ code-point 9)
316 collect (decode-char 'ucs fixnum))
317 "")
318 body)))))))
319 (with-all-digits
320 (Assert-reading-rationals
321 (t 1 "1" "#b1" "#o1" "#x1" "#2r1" "#20r1" "#2000r1")
322 (t 0 "-0" "#b0" "#o0" "#x0" "#1r0" "#2r0" "#20r0" "#2000r0")
323 (t -1 "-1" "#b-1" "#o-1" "#x-1" "#2r-1" "#20r-1" "#2000r-1")
324 (t 1073741823 "#b111111111111111111111111111111" "#o7777777777"
325 "#x3fffffff" "#32rVVVVVV")
326 (t -1073741824 "#b-1000000000000000000000000000000" "#o-10000000000"
327 "#x-40000000" "#32r-1000000")
328 ((featurep 'ratio)
329 1 "1/1" "2/2" "#b1/1" "#o2/2" "#x3/3" "#2r1/1" "#20r2000/2000")
330 ((featurep 'ratio)
331 -1 "-1/1" "-2/2" "#b-1/1" "#o-2/2" "#x-3/3" "#2r-1/1"
332 "#20r-2000/2000"))
333 (Check-Error invalid-read-syntax (read "1234567/0"))
334 (Check-Error invalid-read-syntax (read "#x1234567/0"))
335 (Check-Error invalid-read-syntax (read "#20000r1234567/0"))
336 ;; Unintuitive, but that's the Common Lisp behaviour. Maybe we should
337 ;; error.
338 (Assert (symbolp (read "1234/-123")))))
339
340 ;;; end of lisp-reader-tests.el