|
14 | 14 | (define (init-chunk-number id)
|
15 | 15 | (free-identifier-mapping-put! chunk-numbers id 2)))
|
16 | 16 |
|
17 |
| -(define-syntax-rule (define-chunk chunk-id racketblock) |
18 |
| - (define-syntax (chunk-id stx) |
19 |
| - (syntax-case stx () |
20 |
| - [(_ name expr (... ...)) |
21 |
| - ;; no need for more error checking, using chunk for the code will do that |
22 |
| - (identifier? #'name) |
23 |
| - (let* ([n (get-chunk-number (syntax-local-introduce #'name))] |
24 |
| - [str (symbol->string (syntax-e #'name))] |
25 |
| - [tag (format "~a:~a" str (or n 1))]) |
26 |
| - |
27 |
| - (when n |
28 |
| - (inc-chunk-number (syntax-local-introduce #'name))) |
29 |
| - |
30 |
| - (syntax-local-lift-expression #'(quote-syntax (a-chunk name expr (... ...)))) |
31 |
| - |
32 |
| - (with-syntax ([tag tag] |
33 |
| - [str str] |
34 |
| - [((for-label-mod (... ...)) (... ...)) |
35 |
| - (map (lambda (expr) |
36 |
| - (syntax-case expr (require) |
37 |
| - [(require mod (... ...)) |
38 |
| - (let loop ([mods (syntax->list #'(mod (... ...)))]) |
39 |
| - (cond |
40 |
| - [(null? mods) null] |
41 |
| - [else |
42 |
| - (syntax-case (car mods) (for-syntax) |
43 |
| - [(for-syntax x (... ...)) |
44 |
| - (append (loop (syntax->list #'(x (... ...)))) |
45 |
| - (loop (cdr mods)))] |
46 |
| - [x |
47 |
| - (cons #'x (loop (cdr mods)))])]))] |
48 |
| - [else null])) |
49 |
| - (syntax->list #'(expr (... ...))))] |
50 |
| - |
51 |
| - [(rest (... ...)) (if n |
52 |
| - #`((subscript #,(format "~a" n))) |
53 |
| - #`())]) |
54 |
| - #`(begin |
55 |
| - (require (for-label for-label-mod (... ...) (... ...))) |
56 |
| - #,@(if n |
| 17 | +(define-for-syntax ((make-chunk racketblock) stx) |
| 18 | + (syntax-case stx () |
| 19 | + [(_ name expr ...) |
| 20 | + ;; no need for more error checking, using chunk for the code will do that |
| 21 | + (identifier? #'name) |
| 22 | + (let* ([n (get-chunk-number (syntax-local-introduce #'name))] |
| 23 | + [str (symbol->string (syntax-e #'name))] |
| 24 | + [tag (format "~a:~a" str (or n 1))]) |
| 25 | + |
| 26 | + (when n |
| 27 | + (inc-chunk-number (syntax-local-introduce #'name))) |
| 28 | + |
| 29 | + (syntax-local-lift-expression #'(quote-syntax (a-chunk name expr ...))) |
| 30 | + |
| 31 | + (with-syntax ([tag tag] |
| 32 | + [str str] |
| 33 | + [((for-label-mod ...) ...) |
| 34 | + (map (lambda (expr) |
| 35 | + (syntax-case expr (require) |
| 36 | + [(require mod ...) |
| 37 | + (let loop ([mods (syntax->list #'(mod ...))]) |
| 38 | + (cond |
| 39 | + [(null? mods) null] |
| 40 | + [else |
| 41 | + (syntax-case (car mods) |
| 42 | + (for-syntax quote submod) |
| 43 | + [(submod ".." . _) |
| 44 | + (loop (cdr mods))] |
| 45 | + [(submod "." . _) |
| 46 | + (loop (cdr mods))] |
| 47 | + [(quote x) |
| 48 | + (loop (cdr mods))] |
| 49 | + [(for-syntax x ...) |
| 50 | + (append (loop (syntax->list #'(x ...))) |
| 51 | + (loop (cdr mods)))] |
| 52 | + [x |
| 53 | + (cons #'x (loop (cdr mods)))])]))] |
| 54 | + [else null])) |
| 55 | + (syntax->list #'(expr ...)))] |
| 56 | + |
| 57 | + [(rest ...) (if n |
| 58 | + #`((subscript #,(format "~a" n))) |
| 59 | + #`())]) |
| 60 | + #`(begin |
| 61 | + (require (for-label for-label-mod ... ...)) |
| 62 | + #,@(if n |
57 | 63 | #'()
|
58 | 64 | #'((define-syntax name (make-element-id-transformer
|
59 | 65 | (lambda (stx) #'(chunkref name))))
|
60 | 66 | (begin-for-syntax (init-chunk-number #'name))))
|
61 |
| - (make-splice |
62 |
| - (list (make-toc-element |
63 |
| - #f |
64 |
| - (list (elemtag '(chunk tag) |
65 |
| - (bold (italic (racket name)) " ::="))) |
66 |
| - (list (smaller (elemref '(chunk tag) #:underline? #f |
67 |
| - str |
68 |
| - rest (... ...))))) |
69 |
| - (racketblock expr (... ...)))))))]))) |
| 67 | + (make-splice |
| 68 | + (list (make-toc-element |
| 69 | + #f |
| 70 | + (list (elemtag '(chunk tag) |
| 71 | + (bold (italic (racket name)) " ::="))) |
| 72 | + (list (smaller (elemref '(chunk tag) #:underline? #f |
| 73 | + str |
| 74 | + rest ...)))) |
| 75 | + (racketblock expr ...))))))])) |
70 | 76 |
|
71 |
| -(define-chunk chunk racketblock) |
72 |
| -(define-chunk CHUNK RACKETBLOCK) |
| 77 | +(define-syntax chunk (make-chunk #'racketblock)) |
| 78 | +(define-syntax CHUNK (make-chunk #'RACKETBLOCK)) |
73 | 79 |
|
74 | 80 | (define-syntax (chunkref stx)
|
75 | 81 | (syntax-case stx ()
|
|
0 commit comments