-
Notifications
You must be signed in to change notification settings - Fork 1
/
process.rkt
53 lines (49 loc) · 1.21 KB
/
process.rkt
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
;; A facility to process documents
#lang racket/base
(#%declare #:unsafe)
(provide doc-process)
(require racket/match
"doc.rkt")
(define (doc-process f doc)
(match doc
[(struct* :text ()) doc]
[(struct* :newline ()) doc]
[(struct* :concat ([a a] [b b]))
(define a* (f a))
(define b* (f b))
(cond
[(and (eq? a* a) (eq? b* b)) doc]
[else (concat a* b*)])]
[(struct* :alternatives ([a a] [b b]))
(define a* (f a))
(define b* (f b))
(cond
[(and (eq? a* a) (eq? b* b)) doc]
[else (alternatives a* b*)])]
[(struct* :align ([d d]))
(define d* (f d))
(cond
[(eq? d* d) doc]
[else (align d*)])]
[(struct* :reset ([d d]))
(define d* (f d))
(cond
[(eq? d* d) doc]
[else (reset d*)])]
[(struct* :nest ([n n] [d d]))
(define d* (f d))
(cond
[(eq? d* d) doc]
[else (nest n d*)])]
[(struct* :full ([d d]))
(define d* (f d))
(cond
[(eq? d* d) doc]
[else (full d*)])]
[(struct* :cost ([n n] [d d]))
(define d* (f d))
(cond
[(eq? d* d) doc]
[else (cost n d*)])]
[(struct* :special ()) doc]
[(struct* :fail ()) fail]))