wave of mutilation

pull/111/head
Matthew Butterick 9 years ago
parent 0b2ff83c80
commit 54a25039e5

@ -7,55 +7,55 @@
(rename-out [dialect-module-begin #%module-begin])) (rename-out [dialect-module-begin #%module-begin]))
(define-syntax-rule (dialect-module-begin PARSER-MODE-IN OUTER-EXPR ...) (define-syntax-rule (dialect-module-begin <parser-mode-in> <outer-expr> ...)
(#%module-begin (#%module-begin
(require racket/base) (require racket/base)
(provide (except-out (all-from-out racket/base) #%module-begin) (provide (except-out (all-from-out racket/base) #%module-begin)
(rename-out [pollen-module-begin #%module-begin])) (rename-out [pollen-module-begin #%module-begin]))
(define-syntax (pollen-module-begin stx) (define-syntax (pollen-module-begin stx)
(syntax-case stx () (syntax-case stx ()
[(_ EXPR (... ...)) [(_ <expr> (... ...))
(let-values ([(meta-hash expr-without-metas) (split-metas (syntax->datum #'(EXPR (... ...))) (setup:define-meta-name))]) (let-values ([(meta-hash expr-without-metas) (split-metas (syntax->datum #'(<expr> (... ...))) (setup:define-meta-name))])
(with-syntax ([META-HASH (datum->syntax #f meta-hash)] (with-syntax ([<meta-hash> meta-hash]
[(EXPR-WITHOUT-METAS (... ...)) (datum->syntax #f expr-without-metas)] [(<expr-without-metas> (... ...)) expr-without-metas]
[METAS (format-id #f "~a" (setup:meta-export))] [<metas> (format-id #f "~a" (setup:meta-export))]
[META-MOD (format-symbol "~a" (setup:meta-export))] [<meta-mod> (format-symbol "~a" (setup:meta-export))]
[ROOT (format-id #f "~a" (setup:main-root-node))] [<root> (format-id #f "~a" (setup:main-root-node))]
[NEWLINE (datum->syntax #f (setup:newline))] [<newline> (datum->syntax #f (setup:newline))]
[MODE-PAGETREE (datum->syntax #f default-mode-pagetree)] [<mode-pagetree> default-mode-pagetree]
[MODE-MARKUP (datum->syntax #f default-mode-markup)] [<mode-markup> default-mode-markup]
[MODE-MARKDOWN (datum->syntax #f default-mode-markdown)] [<mode-markdown> default-mode-markdown]
[SPLICING_TAG (datum->syntax #f (setup:splicing-tag))] [<splicing_tag> (setup:splicing-tag)]
[DOC (format-id #f "~a" (setup:main-export))] [<doc> (format-id #f "~a" (setup:main-export))]
[DOC-RAW (generate-temporary 'pollen-)]); prevents conflicts with other imported Pollen sources [<doc-raw> (generate-temporary 'pollen-)]); prevents conflicts with other imported Pollen sources
(replace-context #'(EXPR (... ...)) (replace-context #'(<expr> (... ...))
#'(#%module-begin #'(#%module-begin
(module META-MOD racket/base (module <meta-mod> racket/base
(provide METAS) (provide <metas>)
(define METAS META-HASH)) (define <metas> <meta-hash>))
(module inner pollen/private/doclang-raw (module inner pollen/private/doclang-raw
DOC-RAW ; positional arg for doclang-raw that sets name of export. <doc-raw> ; positional arg for doclang-raw that sets name of export.
(require pollen/top pollen/setup pollen/core) (require pollen/top pollen/setup pollen/core)
(require (submod ".." META-MOD)) (require (submod ".." <meta-mod>))
(provide (all-defined-out) #%top (all-from-out (submod ".." META-MOD) pollen/core)) (provide (all-defined-out) #%top (all-from-out (submod ".." <meta-mod>) pollen/core))
EXPR-WITHOUT-METAS (... ...)) <expr-without-metas> (... ...))
(require 'inner) (require 'inner)
(define DOC (define <doc>
(let* ([parser-mode-undefined? (procedure? inner:parser-mode)] ; if undefined, #%top makes it a procedure (let* ([parser-mode-undefined? (procedure? inner:parser-mode)] ; if undefined, #%top makes it a procedure
[parser-mode (if parser-mode-undefined? PARSER-MODE-IN inner:parser-mode)] [parser-mode (if parser-mode-undefined? <parser-mode-in> inner:parser-mode)]
[proc (cond [proc (case parser-mode
[(eq? parser-mode 'MODE-PAGETREE) decode-pagetree] [(<mode-pagetree>) decode-pagetree]
[(eq? parser-mode 'MODE-MARKUP) (λ(xs) (apply ROOT xs))] ; if `root` undefined, it becomes a default tag function [(<mode-markup>) (λ(xs) (apply <root> xs))] ; if `root` undefined, it becomes a default tag function
[(eq? parser-mode 'MODE-MARKDOWN) [(<mode-markdown>)
(λ(xs) (apply ROOT (map strip-empty-attrs ((dynamic-require 'markdown 'parse-markdown) (apply string-append (map to-string xs))))))] (λ(xs) (apply <root> (map strip-empty-attrs ((dynamic-require 'markdown 'parse-markdown) (apply string-append (map to-string xs))))))]
[else (λ(xs) (apply string-append (map to-string xs)))])] ; string output for preprocessor [else (λ(xs) (apply string-append (map to-string xs)))])] ; string output for preprocessor
;; drop leading newlines, as they're often the result of `defines` and `requires` ;; drop leading newlines, as they're often the result of `defines` and `requires`
[doc-elements (or (memf (λ(ln) (not (equal? ln NEWLINE))) DOC-RAW) null)] [doc-elements (or (memf (λ(ln) (not (equal? ln <newline>))) <doc-raw>) null)]
[doc-elements-spliced (splice doc-elements 'SPLICING_TAG)]) [doc-elements-spliced (splice doc-elements '<splicing_tag>)])
(proc doc-elements-spliced))) (proc doc-elements-spliced)))
(provide DOC METAS (except-out (all-from-out 'inner) DOC-RAW #%top))))))])) (provide <doc> <metas> (except-out (all-from-out 'inner) <doc-raw> #%top))))))]))
OUTER-EXPR ...)) <outer-expr> ...))

@ -1 +1 @@
1459539451 1459991298

Loading…
Cancel
Save