forked from arclanguage/anarki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable-rw.arc
59 lines (49 loc) · 1.47 KB
/
table-rw.arc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
; taken from http://awwx.ws/table-rw3.arc with slight modifications
; - Mark Huetsch
(load "lib/extend.arc")
(load "lib/scheme.arc")
(load "lib/util.arc")
(load "lib/skipwhite.arc")
(def parse-table-items (port (o acc (table)))
(scheme.skip-whitespace port)
(if (is (peekc port) #\})
(do (readc port) acc)
(with (k (read port)
v (read port))
(= (acc k) v)
(parse-table-items port acc))))
(extend-readtable #\{ parse-table-items)
; need the errsafe on type tests because (type x) croaks on
; non-Arc types
(extend ac-literal (x) (errsafe:isa x 'table)
scheme-t)
(def print-table (f x s)
(scheme.display "{" s)
(between (k v) x (scheme.display " " s)
(write k s)
(scheme.display " " s)
(write v s))
(scheme.display "}" s))
(def print-cdr (f x s)
(if (no x)
(scheme.display ")" s)
(errsafe:acons x)
(do (scheme.display " " s)
(print f (car x) s)
(print-cdr f (cdr x) s))
(do (scheme.display " . " s)
(print f x s)
(scheme.display ")" s))))
(def print (f x s)
(if (errsafe:acons x)
(do (scheme.display "(" s)
(print f (car x) s)
(print-cdr f (cdr x) s))
(errsafe:isa x 'table)
(print-table f x s)
(f x s))
(unless (and (bound 'explicit-flush) explicit-flush) (scheme.flush-output s)))
(def disp (x (o s (stdout)))
(print scheme.display x s))
(def write (x (o s (stdout)))
(print scheme.write x s))