From 6c7a0aae5168005ffcd2dbbed22e79cdb64e5ffd Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Mon, 16 Feb 2009 06:30:41 +0000 Subject: [PATCH] Adds a #:part option to `chunk', to control how it's displayed. svn: r13654 --- collects/games/chat-noir/README | 17 ++++++----------- collects/games/chat-noir/chat-noir-literate.ss | 2 +- .../games/chat-noir/literate-doc-wrapper.ss | 14 ++++++++++---- collects/games/chat-noir/literate-lang.ss | 6 ++++++ 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/collects/games/chat-noir/README b/collects/games/chat-noir/README index e1f9b96c67..41e01f513d 100644 --- a/collects/games/chat-noir/README +++ b/collects/games/chat-noir/README @@ -15,21 +15,16 @@ Games. - literate-reader.ss: the reader used for chat-noir-literate.ss to put it into the literate-lang.ss. +Files that begin with "literate" are the files that need to move to a +scribble library, if this experiment is successful. + Problems: - the code is not hyperlinked in the scribble output-- this is due to the confusion about how the requires should work in the two modes. - - The char-noir-doc.ss file contains code that should move into - scribble proper; ideally that file should just be (something like): - - #lang scribble/doc - @include-literate["chat-noir-literate.ss"] - - and it should be built when setup-plt runs on this collection to - build the documentation, ie, this file should eventually be merged - together with ../scribblings/chat-noir.scrbl. - - - @chunks in the TOC + - The char-noir-doc.ss file should be built when setup-plt runs on + this collection to build the documentation, ie, this file should + eventually be merged together with ../scribblings/chat-noir.scrbl. - hyperlink bound top-level identifiers to their bindings? diff --git a/collects/games/chat-noir/chat-noir-literate.ss b/collects/games/chat-noir/chat-noir-literate.ss index 1fe156a9b6..e62a34950f 100644 --- a/collects/games/chat-noir/chat-noir-literate.ss +++ b/collects/games/chat-noir/chat-noir-literate.ss @@ -7,7 +7,7 @@ Chat Noir. What a game. -@chunk[
+@chunk[#:part section
diff --git a/collects/games/chat-noir/literate-doc-wrapper.ss b/collects/games/chat-noir/literate-doc-wrapper.ss index c10ebe9776..85ab4f3e6c 100644 --- a/collects/games/chat-noir/literate-doc-wrapper.ss +++ b/collects/games/chat-noir/literate-doc-wrapper.ss @@ -13,10 +13,15 @@ ;; of the same name (define chunk-number (make-free-identifier-mapping))) -;; define `chunk' as a macro that typesets the code +;; This is the doc-view implementation of `chunk', see "literate-lang.ss" for +;; the cide-view implementation. Defines `chunk' as a macro that typesets the +;; contained code. (define-syntax (chunk stx) (syntax-case stx () - [(_ name expr ...) + [(_ #:part #f name expr ...) + #'(make-splice (list (bold (scheme name) " ::=") + (schemeblock expr ...)))] + [(_ #:part part-function name expr ...) (let ([n (add1 (free-identifier-mapping-get chunk-number #'name (lambda () 0)))]) (free-identifier-mapping-put! chunk-number #'name n) @@ -25,8 +30,9 @@ [(more ...) (if (n . > . 1) #`((subscript #,(format "~a" n))) #`())]) - #'(make-splice (list (subsection #:tag tag (scheme name) more ...) - (schemeblock expr ...)))))])) + #'(make-splice (list (part-function #:tag tag (scheme name) more ...) + (schemeblock expr ...)))))] + [(_ name expr ...) #'(chunk #:part subsection name expr ...)])) ;; HACK: provide a fake `module', which makes it possible to include a module ;; and get only its code in. diff --git a/collects/games/chat-noir/literate-lang.ss b/collects/games/chat-noir/literate-lang.ss index 73a1df856e..aac26b9daf 100644 --- a/collects/games/chat-noir/literate-lang.ss +++ b/collects/games/chat-noir/literate-lang.ss @@ -25,8 +25,14 @@ chunks id `(,@(mapping-get chunks id) ,@(map syntax-local-introduce exprs))))) +;; This is the code-view implementation of `chunk', see +;; "literate-doc-wrapper.ss" for the doc-view implementation. Defines +;; `chunk' as a macro that collects the code to be later reassembled +;; by `tangle'. (define-syntax (chunk stx) (syntax-case stx () + ;; no use for the part function here + [(_ #:part part-function name expr ...) (chunk name expr ...)] [(_ name expr ...) (cond [(not (identifier? #'name)) (raise-syntax-error #f "expected a chunk name" stx #'name)]