Skip to content

Commit e1ff6f1

Browse files
committed
Fixed scribble bug #15. Also cleaned up code by currying the racketblock vs RACKETBLOCK parameter for chunk and CHUNK instead of calling define-syntax-rule twice.
1 parent c34a69c commit e1ff6f1

File tree

1 file changed

+57
-51
lines changed
  • scribble-lib/scribble/private

1 file changed

+57
-51
lines changed

scribble-lib/scribble/private/lp.rkt

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,62 +14,68 @@
1414
(define (init-chunk-number id)
1515
(free-identifier-mapping-put! chunk-numbers id 2)))
1616

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
5763
#'()
5864
#'((define-syntax name (make-element-id-transformer
5965
(lambda (stx) #'(chunkref name))))
6066
(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 ...))))))]))
7076

71-
(define-chunk chunk racketblock)
72-
(define-chunk CHUNK RACKETBLOCK)
77+
(define-syntax chunk (make-chunk #'racketblock))
78+
(define-syntax CHUNK (make-chunk #'RACKETBLOCK))
7379

7480
(define-syntax (chunkref stx)
7581
(syntax-case stx ()

0 commit comments

Comments
 (0)