tidy core

pull/84/head
Matthew Butterick 9 years ago
parent fde0d806fb
commit 9e1fadc94b

@ -1,38 +1,34 @@
#lang racket/base #lang racket/base
(require (for-syntax racket/base racket/syntax pollen/world) pollen/decode pollen/pagetree racket/list pollen/world markdown) (require (for-syntax racket/base syntax/strip-context racket/syntax pollen/world) pollen/decode pollen/pagetree racket/list pollen/world markdown)
(provide (all-defined-out) (all-from-out pollen/world)) (provide (all-defined-out) (all-from-out pollen/world))
(define-syntax-rule (define+provide-module-begin-in-mode MODE-ARG) (define-syntax-rule (define+provide-module-begin-in-mode PARSER-MODE-ARG)
(begin (begin
(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 (... ...))
(with-syntax ([EXPRS #'(expr (... ...))]) (with-syntax ([DOC (format-id #'(EXPR (... ...)) "~a" (world:current-main-export))])
(datum->syntax #'EXPRS (replace-context #'(EXPR (... ...))
`(#%module-begin #'(#%module-begin
(module inner pollen/doclang-raw ; exports result as doc-raw (module inner pollen/doclang-raw ; exports result as doc-raw
(require pollen/top pollen/world) (require pollen/top pollen/world)
(provide #%top (all-defined-out) (all-from-out pollen/world)) (provide #%top (all-defined-out) (all-from-out pollen/world))
,@(syntax->datum #'EXPRS)) EXPR (... ...))
(require 'inner) (require 'inner)
(define ,(world:current-main-export) (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 (if parser-mode-undefined? PARSER-MODE-ARG inner:parser-mode)]
MODE-ARG [proc (cond
inner:parser-mode)] [(eq? parser-mode world:mode-pagetree) (λ xs (decode-pagetree xs))]
[proc (cond [(eq? parser-mode world:mode-markup) root] ; if `root` undefined, it becomes a default tag function
[(eq? parser-mode world:mode-pagetree) (λ xs (decode-pagetree xs))] [(eq? parser-mode world:mode-markdown)
[(eq? parser-mode world:mode-markup) root] ; if `root` undefined, it becomes a default tag function (λ xs (apply root (apply (compose1 parse-markdown string-append) (map to-string xs))))]
[(eq? parser-mode world:mode-markdown) [else ; for preprocessor output, just make a string
(λ xs (apply root (apply (compose1 parse-markdown string-append) (λ xs (apply string-append (map to-string xs)))])]
(map to-string xs))))] ;; drop leading newlines, as they're often the result of `defines` and `requires`
[else ; for preprocessor output, just make a string [doc-elements (dropf doc-raw (λ(ln) (equal? ln "\n")))])
(λ xs (apply string-append (map to-string xs)))])] (apply proc doc-elements)))
[doc-elements (if (list? doc-raw) ; discard all newlines at front of multi-line file (provide DOC (except-out (all-from-out 'inner) doc-raw #%top)))))])))) ; hide internal exports
(dropf doc-raw (λ(ln) (equal? ln "\n")))
doc-raw)]) ; single line
(apply proc doc-elements)))
(provide ,(world:current-main-export) (except-out (all-from-out 'inner) doc-raw #%top))) #'EXPRS))])))) ; hide internal exports

@ -55,28 +55,34 @@
reader-mode)) reader-mode))
(define meta-keys-plus-here (cons (world:current-here-path-key) meta-keys)) ; here-path at front so it can be overridden (define meta-keys-plus-here (cons (world:current-here-path-key) meta-keys)) ; here-path at front so it can be overridden
(define meta-values-plus-here (cons reader-here-path meta-values)) (define meta-values-plus-here (cons reader-here-path meta-values))
(with-syntax* ([(KEY ...) (datum->syntax source-stx meta-keys-plus-here)] (with-syntax ([(KEY ...) (datum->syntax source-stx meta-keys-plus-here)]
[(VALUE ...) (datum->syntax source-stx meta-values-plus-here)] [(VALUE ...) (datum->syntax source-stx meta-values-plus-here)]
[KVS #'(append (list 'KEY VALUE) ...)]) [METAS (format-id source-stx "~a" (world:current-meta-export))]
[META-MOD (format-symbol "~a" (world:current-meta-export))]
[POLLEN-MOD (format-symbol "~a" 'pollen-lang-module)]
[DOC (format-id source-stx "~a" (world:current-main-export))]
[PARSER-MODE-VALUE (format-symbol "~a" parser-mode)]
[DIRECTORY-REQUIRES (datum->syntax source-stx (require+provide-directory-require-files path-string))]
[(SOURCE-LINE ...) (datum->syntax source-stx meta-free-file-data)])
(syntax-property (syntax-property
(datum->syntax source-stx (replace-context source-stx
`(module runtime-wrapper racket/base #'(module runtime-wrapper racket/base
(module metas racket/base (module META-MOD racket/base
(provide (all-defined-out)) (provide (all-defined-out))
(define ,(world:current-meta-export) (apply hash ,(syntax->datum #'KVS)))) (define METAS (apply hash (append (list 'KEY VALUE) ...))))
(module pollen-lang-module pollen (module POLLEN-MOD pollen
(define parser-mode ',parser-mode) ; change names of exports for local use, to avoid conflicts (define parser-mode 'PARSER-MODE-VALUE)
(provide (except-out (all-defined-out) parser-mode) (provide (except-out (all-defined-out) parser-mode)
(prefix-out inner: parser-mode)) (prefix-out inner: parser-mode)) ; avoids conflicts with importing modules
,(require+provide-directory-require-files path-string) DIRECTORY-REQUIRES
(require (submod ".." ".." metas)) ; get metas from adjacent submodule (require (submod ".." ".." META-MOD)) ; get metas from adjacent submodule
(provide (all-from-out (submod ".." ".." metas))) (provide (all-from-out (submod ".." ".." META-MOD)))
,@meta-free-file-data) SOURCE-LINE ...)
(require (submod pollen/runtime-config show) 'pollen-lang-module) (require (submod pollen/runtime-config show) 'POLLEN-MOD)
(provide (all-from-out 'pollen-lang-module)) (provide (all-from-out 'POLLEN-MOD))
(show ,(world:current-main-export) inner:parser-mode)) source-stx) (show DOC inner:parser-mode)))
'module-language 'module-language
'#(pollen/language-info get-language-info #f))))) '#(pollen/language-info get-language-info #f)))))

Loading…
Cancel
Save