add decimal number to toplevel readtable

This commit is contained in:
Peter McGoron 2024-10-13 10:48:30 -04:00
parent b09ae09125
commit 0dab772a77
1 changed files with 21 additions and 0 deletions

View File

@ -34,6 +34,16 @@
;;; ;;;
;;; All tokens are procedure-encapsulated objects, since the reader should ;;; All tokens are procedure-encapsulated objects, since the reader should
;;; never return a literal procedure. Each procedure has a TYPE message. ;;; never return a literal procedure. Each procedure has a TYPE message.
;;;
;;; ;;;;;;;;;;;;;;;
;;; Possible Improvements
;;; ;;;;;;;;;;;;;;;
;;;
;;; * A coherent API.
;;; * regex-based lexer.
;;; * A way to load readtables and read functions when the function is run,
;;; and not when functions are defined, without sacrificing performance.
;;; * Better Unicode handling.
(load "chez-compat.scm") (load "chez-compat.scm")
(load "util.scm") (load "util.scm")
@ -948,6 +958,14 @@
port))) port)))
(list readtable:update %bol readtable:vector))) (list readtable:update %bol readtable:vector)))
;;; Read a decimal number without prefixes.
(define readtable:create-number
(lambda (toplevel number-char _ port)
(readtable:act readtable:read-sign
number-char
(read:number-builder readtable:for-dec)
port)))
;;; ;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;
;;; Toplevel reader. ;;; Toplevel reader.
;;; ;;;;;;;;;;;;;;;; ;;; ;;;;;;;;;;;;;;;;
@ -963,6 +981,8 @@
(list readtable:update %eol (readtable:error 'top "unbalanced list")) (list readtable:update %eol (readtable:error 'top "unbalanced list"))
(list readtable:update #\# (readtable:next/old-as-acc (list readtable:update #\# (readtable:next/old-as-acc
readtable:hash)) readtable:hash))
(list readtable:update '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
readtable:create-number)
(list readtable:update #\; (list readtable:update #\;
(readtable:jump-discard readtable:read-to-newline))))) (readtable:jump-discard readtable:read-to-newline)))))
@ -1061,3 +1081,4 @@
(read-all "#e10.5") (read-all "#e10.5")
(read-all "#d10.24f12") (read-all "#d10.24f12")
(read-all "#d-i") (read-all "#d-i")
(read-all "100i")