diff options
| author | 2024-09-22 00:00:26 -0400 | |
|---|---|---|
| committer | 2024-09-22 00:00:26 -0400 | |
| commit | e109c255ad28591a40b994d1d38c6816443e4aa4 (patch) | |
| tree | 7a2d834ba66909e65c3131064f40f940b9cc6f6d /read.scm | |
| parent | read: factor out improper list reader (diff) | |
read: vectors
Diffstat (limited to 'read.scm')
| -rw-r--r-- | read.scm | 38 |
1 files changed, 37 insertions, 1 deletions
@@ -139,6 +139,11 @@ (map:val node)))) (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. (define readtable:update (lambda (table char action) @@ -196,6 +201,13 @@ (lambda (oldtable 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 ;;; ;;;;;;;;;;;;;;;;; @@ -339,7 +351,29 @@ readtable:read-improper-cdr) 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. +;;; ;;;;;;;;;;;;;;;; ;;; This is defined as a function so that it dynamically loads each ;;; sub-readtable. (define readtable:top @@ -350,6 +384,8 @@ (list readtable:update #f (readtable:return 'eof)) (list readtable:update %bol readtable:read-list) (list readtable:update %eol (readtable:error "unbalanced list")) + (list readtable:update #\# (readtable:next/old-as-acc + readtable:hash)) (list readtable:update #\; (readtable:jump-discard readtable:read-to-newline))))) @@ -387,4 +423,4 @@ (read-all "(a b c def (ghi j) k )") (read-all "( a . b )") (read-all "( a .b . c)") - +(read-all "#( a b y)") |
