From e581f8ceb7d994b869b23a457c9cf31eaba6a81c Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Mon, 16 Feb 2009 04:33:54 +0000 Subject: [PATCH] use a counter to get separate tags and section titles svn: r13653 original commit: 9d06dd7f579015518ed07994c2c733a3bc74d8bc --- .../games/chat-noir/literate-doc-wrapper.ss | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/collects/games/chat-noir/literate-doc-wrapper.ss b/collects/games/chat-noir/literate-doc-wrapper.ss index a5a0a587..c10ebe97 100644 --- a/collects/games/chat-noir/literate-doc-wrapper.ss +++ b/collects/games/chat-noir/literate-doc-wrapper.ss @@ -3,16 +3,30 @@ ;; Use this module to create literate doc wrappers -- files that require the ;; literate code in a way that makes it a scribble file. -(provide include chunk - (all-from-out scribble/manual)) +(provide include chunk (all-from-out scribble/manual)) -(require scribble/manual scribble/decode scheme/include) +(require scribble/manual scribble/decode scheme/include + (for-syntax scheme/base syntax/boundmap)) + +(begin-for-syntax + ;; maps chunk identifiers to a counter, so we can distinguish multiple uses + ;; of the same name + (define chunk-number (make-free-identifier-mapping))) ;; define `chunk' as a macro that typesets the code -(define-syntax-rule (chunk name expr ...) - (make-splice (list (subsection #:tag (format "~a" 'name) - (scheme name)) - (schemeblock expr ...)))) +(define-syntax (chunk stx) + (syntax-case stx () + [(_ name expr ...) + (let ([n (add1 (free-identifier-mapping-get + chunk-number #'name (lambda () 0)))]) + (free-identifier-mapping-put! chunk-number #'name n) + (with-syntax ([tag (format "~a~a" (syntax->datum #'name) + (if (n . > . 1) (format ":~a" n) ""))] + [(more ...) (if (n . > . 1) + #`((subscript #,(format "~a" n))) + #`())]) + #'(make-splice (list (subsection #:tag tag (scheme name) more ...) + (schemeblock expr ...)))))])) ;; HACK: provide a fake `module', which makes it possible to include a module ;; and get only its code in.