finished fixing multiple chunks
svn: r13841
This commit is contained in:
parent
973f08e011
commit
42adbca527
|
@ -4,10 +4,6 @@ Games.
|
||||||
|
|
||||||
Problems:
|
Problems:
|
||||||
|
|
||||||
- handling multiple chunks is broken right now, so the
|
|
||||||
chunkref-introducting macro (in scribble/private/lp.ss)
|
|
||||||
is disabled.
|
|
||||||
|
|
||||||
- Need to make 'a-chunk' be a real macro, I expect. (used in
|
- Need to make 'a-chunk' be a real macro, I expect. (used in
|
||||||
scribble/private/lp.ss)
|
scribble/private/lp.ss)
|
||||||
|
|
||||||
|
@ -15,8 +11,6 @@ Problems:
|
||||||
|
|
||||||
- do unbound chunk ids signal syntax errors? How about unused ones?
|
- do unbound chunk ids signal syntax errors? How about unused ones?
|
||||||
|
|
||||||
- toc entries should not be underlined.
|
|
||||||
|
|
||||||
To document:
|
To document:
|
||||||
|
|
||||||
@chunk
|
@chunk
|
||||||
|
|
|
@ -7,34 +7,28 @@
|
||||||
;; maps chunk identifiers to a counter, so we can distinguish multiple uses
|
;; maps chunk identifiers to a counter, so we can distinguish multiple uses
|
||||||
;; of the same name
|
;; of the same name
|
||||||
(define chunk-numbers (make-free-identifier-mapping))
|
(define chunk-numbers (make-free-identifier-mapping))
|
||||||
(define (get-chunk-number id install?)
|
(define (get-chunk-number id)
|
||||||
(let ([n (add1 (free-identifier-mapping-get chunk-numbers id
|
(free-identifier-mapping-get chunk-numbers id (lambda () #f)))
|
||||||
(lambda () 0)))])
|
(define (inc-chunk-number id)
|
||||||
(when install?
|
(free-identifier-mapping-put! chunk-numbers id (+ 1 (free-identifier-mapping-get chunk-numbers id))))
|
||||||
(free-identifier-mapping-put! chunk-numbers id n))
|
(define (init-chunk-number id)
|
||||||
n))
|
(free-identifier-mapping-put! chunk-numbers id 2)))
|
||||||
(define (register-chunk-name name)
|
|
||||||
(get-chunk-number name #t)))
|
|
||||||
|
|
||||||
(define-syntax (chunk stx)
|
(define-syntax (chunk stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ name expr ...)
|
[(_ name expr ...)
|
||||||
;; no need for more error checking, using chunk for the code will do that
|
;; no need for more error checking, using chunk for the code will do that
|
||||||
(identifier? #'name)
|
(identifier? #'name)
|
||||||
(let ([n (get-chunk-number (syntax-local-introduce #'name) #f)]
|
(let* ([n (get-chunk-number (syntax-local-introduce #'name))]
|
||||||
[str (symbol->string (syntax-e #'name))])
|
[str (symbol->string (syntax-e #'name))]
|
||||||
|
[tag (format "~a:~a" str (or n 1))])
|
||||||
|
|
||||||
|
(when n
|
||||||
|
(inc-chunk-number (syntax-local-introduce #'name)))
|
||||||
|
|
||||||
(syntax-local-lift-expression #'(quote-syntax (a-chunk name expr ...)))
|
(syntax-local-lift-expression #'(quote-syntax (a-chunk name expr ...)))
|
||||||
|
|
||||||
(if (n . > . 1)
|
(with-syntax ([tag tag]
|
||||||
(let ([str
|
|
||||||
(format
|
|
||||||
"need to handle secondary tags: ~a ~a\n"
|
|
||||||
n
|
|
||||||
str)])
|
|
||||||
#`(begin
|
|
||||||
(italic #,str)))
|
|
||||||
(with-syntax ([tag str]
|
|
||||||
[str str]
|
[str str]
|
||||||
[((for-label-mod ...) ...)
|
[((for-label-mod ...) ...)
|
||||||
(map (lambda (expr)
|
(map (lambda (expr)
|
||||||
|
@ -46,34 +40,41 @@
|
||||||
[else
|
[else
|
||||||
(syntax-case (car mods) (for-syntax)
|
(syntax-case (car mods) (for-syntax)
|
||||||
[(for-syntax x ...)
|
[(for-syntax x ...)
|
||||||
(loop (cdr mods))
|
|
||||||
#;
|
|
||||||
(append (loop (syntax->list #'(x ...)))
|
(append (loop (syntax->list #'(x ...)))
|
||||||
(loop (cdr mods)))]
|
(loop (cdr mods)))]
|
||||||
[x
|
[x
|
||||||
(cons #'x (loop (cdr mods)))])]))]
|
(cons #'x (loop (cdr mods)))])]))]
|
||||||
[else null]))
|
[else null]))
|
||||||
(syntax->list #'(expr ...)))])
|
(syntax->list #'(expr ...)))]
|
||||||
|
|
||||||
|
[(rest ...) (if n
|
||||||
|
#`((subscript #,(format "~a" n)))
|
||||||
|
#`())])
|
||||||
|
|
||||||
#`(begin
|
#`(begin
|
||||||
(require (for-label for-label-mod ... ...))
|
(require (for-label for-label-mod ... ...))
|
||||||
(define-syntax name (make-element-id-transformer
|
#,@(if n
|
||||||
|
#'()
|
||||||
|
#'((define-syntax name (make-element-id-transformer
|
||||||
(lambda (stx) #'(chunkref name))))
|
(lambda (stx) #'(chunkref name))))
|
||||||
(begin-for-syntax (register-chunk-name #'name))
|
(begin-for-syntax (init-chunk-number #'name))))
|
||||||
(make-splice
|
(make-splice
|
||||||
(list (make-toc-element
|
(list (make-toc-element
|
||||||
#f
|
#f
|
||||||
(list (elemtag '(chunk tag)
|
(list (elemtag '(chunk tag)
|
||||||
(bold (italic (scheme name)) " ::=")))
|
(bold (italic (scheme name)) " ::=")))
|
||||||
(list (smaller (elemref '(chunk tag) #:underline? #f
|
(list (smaller (elemref '(chunk tag) #:underline? #f
|
||||||
str))))
|
str
|
||||||
(schemeblock expr ...)))))))]))
|
rest ...))))
|
||||||
|
(schemeblock expr ...))))))]))
|
||||||
|
|
||||||
(define-syntax (chunkref stx)
|
(define-syntax (chunkref stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ id)
|
[(_ id)
|
||||||
(identifier? #'id)
|
(identifier? #'id)
|
||||||
(with-syntax ([str (format "~a" (syntax-e #'id))])
|
(with-syntax ([tag (format "~a:1" (syntax-e #'id))]
|
||||||
#'(elemref '(chunk str) #:underline? #f str))]))
|
[str (format "~a" (syntax-e #'id))])
|
||||||
|
#'(elemref '(chunk tag) #:underline? #f str))]))
|
||||||
|
|
||||||
|
|
||||||
(provide (all-from-out scheme/base
|
(provide (all-from-out scheme/base
|
||||||
|
|
Loading…
Reference in New Issue
Block a user