Simplify doclang #169

Merged
mbutterick merged 2 commits from simplify-doclang into master 7 years ago

@ -10,18 +10,16 @@
(define-syntax (*module-begin stx) (define-syntax (*module-begin stx)
(syntax-case stx () (syntax-case stx ()
[(_ id . body) [(_ id post-process . body)
(with-syntax ([post-process #'(λ (x) x)] (with-syntax ([exprs #'()])
[exprs #'()])
#'(#%module-begin #'(#%module-begin
(doc-begin id post-process exprs . body)))])) (doc-begin id post-process exprs . body)))]))
(define-syntax (doc-begin stx) (define-syntax (doc-begin stx)
(syntax-case stx () (syntax-case stx ()
[(_ m-id post-process (expr ...)) [(_ m-id post-process (expr ...))
#`(begin ;; unlike regular doclang, don't `provide` m-id (we'll do that in main-base wrapper)
(define m-id (post-process (list . #,(reverse (syntax->list #'(expr ...)))))) #`(define m-id (post-process (list . #,(reverse (syntax->list #'(expr ...))))))]
(provide m-id))]
[(_ m-id post-process exprs . body) [(_ m-id post-process exprs . body)
;; `body' probably starts with lots of string constants; it's ;; `body' probably starts with lots of string constants; it's
;; slow to trampoline on every string, so do them in a batch ;; slow to trampoline on every string, so do them in a batch

@ -1,6 +1,7 @@
#lang racket/base #lang racket/base
(require (for-syntax racket/base racket/syntax "../setup.rkt" "split-metas.rkt") (require (for-syntax racket/base racket/syntax "../setup.rkt" "split-metas.rkt")
"to-string.rkt" "../pagetree.rkt" "splice.rkt" "../setup.rkt" "../core.rkt") "to-string.rkt" "../pagetree.rkt" "splice.rkt" "../setup.rkt" "../core.rkt"
(prefix-in doclang: "doclang-raw.rkt"))
(provide (except-out (all-from-out racket/base) #%module-begin) (provide (except-out (all-from-out racket/base) #%module-begin)
(rename-out [dialect-module-begin #%module-begin])) (rename-out [dialect-module-begin #%module-begin]))
@ -51,33 +52,20 @@
[METAS-ID (setup:meta-export)] [METAS-ID (setup:meta-export)]
[META-MOD-ID (setup:meta-export)] [META-MOD-ID (setup:meta-export)]
[ROOT-ID (setup:main-root-node)] [ROOT-ID (setup:main-root-node)]
[DOC-ID (setup:main-export)] [DOC-ID (setup:main-export)])
;; prevents conflicts with other imported Pollen sources #'(doclang:#%module-begin
[DOC-RAW (datum->syntax #'here (syntax->datum (generate-temporary 'pollen-)))]) DOC-ID ; positional arg for doclang-raw: name of export
#'(#%module-begin (λ (xs)
(require pollen/top) ; we could get this via 'inner, but then we'd have to avoid exporting it (define parser-mode (or 'PARSER-MODE-FROM-READER PARSER-MODE-FROM-EXPANDER))
(define proc (make-parse-proc parser-mode ROOT-ID))
(define doc-elements (splice (strip-leading-newlines xs) (setup:splicing-tag)))
(proc doc-elements)) ; positional arg for doclang-raw: post-processor
(module META-MOD-ID racket/base (module META-MOD-ID racket/base
(provide METAS-ID) (provide METAS-ID)
(define METAS-ID META-HASH)) (define METAS-ID META-HASH))
(require pollen/top pollen/core pollen/setup (submod "." META-MOD-ID))
(module inner pollen/private/doclang-raw (provide (all-defined-out) METAS-ID DOC-ID)
DOC-RAW ; positional arg for doclang-raw that sets name of export
(require pollen/top pollen/core pollen/setup (submod ".." META-MOD-ID))
(and (current-metas METAS-ID) "\n") ; because newlines get stripped, voids don't
(provide (all-defined-out) METAS-ID)
. EXPRS-WITHOUT-METAS)
(define prev-metas (current-metas)) (define prev-metas (current-metas))
(require 'inner) (and (current-metas METAS-ID) "\n") ; because newlines get stripped, voids don't
(begin . EXPRS-WITHOUT-METAS)
(define DOC-ID (and (current-metas prev-metas) ""))))])) ; leave behind empty string, not void
;; parser-mode must be resolved at runtime, not compile time
(let* ([parser-mode (or 'PARSER-MODE-FROM-READER PARSER-MODE-FROM-EXPANDER)]
[proc (make-parse-proc parser-mode ROOT-ID)]
[doc-elements (strip-leading-newlines DOC-RAW)]
[doc-elements-spliced (splice doc-elements (setup:splicing-tag))])
(proc doc-elements-spliced)))
(current-metas prev-metas)
(provide DOC-ID (except-out (all-from-out 'inner) DOC-RAW)))))]))

@ -1,8 +1,15 @@
#lang racket/base #lang racket/base
(require racket/string pollen/core)
;; This will prevent tests from littering their directory ;; This will prevent tests from littering their directory
;; with pollen-cache files. ;; with pollen-cache files.
(module setup racket/base (module setup racket/base
(provide (all-defined-out)) (provide (all-defined-out))
(define compile-cache-active #f) (define compile-cache-active #f)
(define render-cache-active #f)) (define render-cache-active #f))
(provide test-current-metas)
(define (test-current-metas)
(if (current-metas)
(string-join (sort (map symbol->string (hash-keys (current-metas))) string<?) " ")
"false"))

@ -0,0 +1,3 @@
#lang racket/base
(require pollen/core "pollen.rkt" rackunit)
(check-equal? (test-current-metas) "false")

@ -0,0 +1,5 @@
#lang pollen
(require rackunit)
(define-meta foo "bar")
(check-equal? (test-current-metas) "foo here-path zim")
(define-meta zim "zam")
Loading…
Cancel
Save