read: vectors
This commit is contained in:
parent
003d6dde05
commit
e109c255ad
38
read.scm
38
read.scm
|
@ -139,6 +139,11 @@
|
||||||
(map:val node))))
|
(map:val node))))
|
||||||
(action table char acc port)))))
|
(action table char acc port)))))
|
||||||
|
|
||||||
|
;;; Run the action in TABLE with the next character from PORT.
|
||||||
|
(define readtable:next
|
||||||
|
(lambda (table acc port)
|
||||||
|
(readtable:act table (port 'read) acc port)))
|
||||||
|
|
||||||
;;; Return a new readtable where CHAR is bound to ACTION.
|
;;; Return a new readtable where CHAR is bound to ACTION.
|
||||||
(define readtable:update
|
(define readtable:update
|
||||||
(lambda (table char action)
|
(lambda (table char action)
|
||||||
|
@ -196,6 +201,13 @@
|
||||||
(lambda (oldtable char acc port)
|
(lambda (oldtable char acc port)
|
||||||
(readtable:act newtable char acc port))))
|
(readtable:act newtable char acc port))))
|
||||||
|
|
||||||
|
;;; Jump to a new readtable, reading the new character, with the old
|
||||||
|
;;; readtable as ACC.
|
||||||
|
(define readtable:next/old-as-acc
|
||||||
|
(lambda (newtable)
|
||||||
|
(lambda (oldtable __ _ port)
|
||||||
|
(readtable:next newtable oldtable port))))
|
||||||
|
|
||||||
;;; ;;;;;;;;;;;;;;;;;
|
;;; ;;;;;;;;;;;;;;;;;
|
||||||
;;; Identifier reader
|
;;; Identifier reader
|
||||||
;;; ;;;;;;;;;;;;;;;;;
|
;;; ;;;;;;;;;;;;;;;;;
|
||||||
|
@ -339,7 +351,29 @@
|
||||||
readtable:read-improper-cdr)
|
readtable:read-improper-cdr)
|
||||||
port)))
|
port)))
|
||||||
|
|
||||||
|
(define readtable:read-proper-list
|
||||||
|
(lambda (table port)
|
||||||
|
(readtable:read-list-loop (readtable:table-for-list
|
||||||
|
table
|
||||||
|
(readtable:error "expected proper list"))
|
||||||
|
port)))
|
||||||
|
|
||||||
|
;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;; Reader for datum that start with "#"
|
||||||
|
;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(define readtable:vector
|
||||||
|
(lambda (_ __ toplevel port)
|
||||||
|
(list 'vector (readtable:read-proper-list toplevel port))))
|
||||||
|
|
||||||
|
(define readtable:hash
|
||||||
|
(readtable:process
|
||||||
|
(readtable:empty/default (readtable:error "unimplemented"))
|
||||||
|
(list readtable:update %bol readtable:vector)))
|
||||||
|
|
||||||
|
;;; ;;;;;;;;;;;;;;;;
|
||||||
;;; Toplevel reader.
|
;;; Toplevel reader.
|
||||||
|
;;; ;;;;;;;;;;;;;;;;
|
||||||
;;; This is defined as a function so that it dynamically loads each
|
;;; This is defined as a function so that it dynamically loads each
|
||||||
;;; sub-readtable.
|
;;; sub-readtable.
|
||||||
(define readtable:top
|
(define readtable:top
|
||||||
|
@ -350,6 +384,8 @@
|
||||||
(list readtable:update #f (readtable:return 'eof))
|
(list readtable:update #f (readtable:return 'eof))
|
||||||
(list readtable:update %bol readtable:read-list)
|
(list readtable:update %bol readtable:read-list)
|
||||||
(list readtable:update %eol (readtable:error "unbalanced list"))
|
(list readtable:update %eol (readtable:error "unbalanced list"))
|
||||||
|
(list readtable:update #\# (readtable:next/old-as-acc
|
||||||
|
readtable:hash))
|
||||||
(list readtable:update #\;
|
(list readtable:update #\;
|
||||||
(readtable:jump-discard readtable:read-to-newline)))))
|
(readtable:jump-discard readtable:read-to-newline)))))
|
||||||
|
|
||||||
|
@ -387,4 +423,4 @@
|
||||||
(read-all "(a b c def (ghi j) k )")
|
(read-all "(a b c def (ghi j) k )")
|
||||||
(read-all "( a . b )")
|
(read-all "( a . b )")
|
||||||
(read-all "( a .b . c)")
|
(read-all "( a .b . c)")
|
||||||
|
(read-all "#( a b y)")
|
||||||
|
|
Loading…
Reference in New Issue