aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2024-10-13 10:48:30 -0400
committerGravatar Peter McGoron 2024-10-13 10:48:30 -0400
commit0dab772a779e13a9c7f4b5ec1577c443ad70ad38 (patch)
tree00d37f41e31fb89ea0d3de2272acdde37f0375ce
parentfix signs, make radix push more precise (diff)
add decimal number to toplevel readtable
-rw-r--r--read.scm21
1 files changed, 21 insertions, 0 deletions
diff --git a/read.scm b/read.scm
index a2b7166..29ab362 100644
--- a/read.scm
+++ b/read.scm
@@ -34,6 +34,16 @@
;;;
;;; All tokens are procedure-encapsulated objects, since the reader should
;;; 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 "util.scm")
@@ -948,6 +958,14 @@
port)))
(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.
;;; ;;;;;;;;;;;;;;;;
@@ -963,6 +981,8 @@
(list readtable:update %eol (readtable:error 'top "unbalanced list"))
(list readtable:update #\# (readtable:next/old-as-acc
readtable:hash))
+ (list readtable:update '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
+ readtable:create-number)
(list readtable:update #\;
(readtable:jump-discard readtable:read-to-newline)))))
@@ -1061,3 +1081,4 @@
(read-all "#e10.5")
(read-all "#d10.24f12")
(read-all "#d-i")
+(read-all "100i")