use `syntax-property` to communicate between reader and expander

pull/111/head
Matthew Butterick 9 years ago
parent c060b8958b
commit ed8581287c

@ -7,7 +7,7 @@
(rename-out [dialect-module-begin #%module-begin]))
(define-syntax-rule (dialect-module-begin PARSER-MODE-IN . OUTER-EXPRS)
(define-syntax-rule (dialect-module-begin PARSER-MODE-FROM-EXPANDER . READER-SUBMOD-AND-OTHER-EXPRS)
(#%module-begin
(require racket/base)
(provide (except-out (all-from-out racket/base) #%module-begin)
@ -16,7 +16,9 @@
(syntax-case stx ()
[(_ . EXPRS)
(let-values ([(meta-hash exprs-without-metas) (split-metas (syntax->datum #'EXPRS) (setup:define-meta-name))])
(with-syntax ([META-HASH meta-hash]
(with-syntax (;; 'parser-mode-from-reader will be #f for an inline submodule
[PARSER-MODE-FROM-READER-PROPERTY (syntax-property stx 'parser-mode-from-reader)]
[META-HASH meta-hash]
[EXPRS-WITHOUT-METAS exprs-without-metas]
[METAS (setup:meta-export)]
[META-MOD (setup:meta-export)]
@ -37,21 +39,18 @@
(module inner pollen/private/doclang-raw
DOC-RAW ; positional arg for doclang-raw that sets name of export.
(require pollen/top pollen/setup pollen/core)
(require (submod ".." META-MOD))
(require pollen/top (submod ".." META-MOD) pollen/core pollen/setup)
(provide (all-defined-out) #%top (all-from-out (submod ".." META-MOD) pollen/core))
. EXPRS-WITHOUT-METAS)
(require 'inner)
(define DOC
(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)]
(let* ([parser-mode (or 'PARSER-MODE-FROM-READER-PROPERTY PARSER-MODE-FROM-EXPANDER)]
[proc (case parser-mode
[(MODE-PAGETREE) decode-pagetree]
[(MODE-MARKUP) (λ(xs) (apply ROOT xs))] ; if `root` undefined, it becomes a default tag function
[(MODE-MARKDOWN)
(λ(xs) (apply ROOT (map strip-empty-attrs ((dynamic-require 'markdown 'parse-markdown) (apply string-append (map to-string xs))))))]
[(MODE-MARKDOWN) (λ(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
;; 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)]
@ -59,4 +58,4 @@
(proc doc-elements-spliced)))
(provide DOC METAS (except-out (all-from-out 'inner) DOC-RAW #%top))))))]))
. OUTER-EXPRS))
. READER-SUBMOD-AND-OTHER-EXPRS))

@ -33,27 +33,27 @@
#:inside? #t)])
(read-inner path-string p)))
(define reader-here-path (path-string->here-path path-string))
(define parser-mode (infer-parser-mode reader-mode reader-here-path))
(define parser-mode-from-reader (infer-parser-mode reader-mode reader-here-path))
(define parsed-syntax
(strip-context
(with-syntax ([HERE-KEY (setup:here-path-key)]
(with-syntax* ([HERE-KEY (setup:here-path-key)]
[HERE-PATH reader-here-path]
[POLLEN-MOD-NAME 'pollen-module]
[PARSER-MODE-VALUE parser-mode]
[DIRECTORY-REQUIRES (require+provide-directory-require-files path-string)]
[SOURCE-LINES source-stx]
[DOC (setup:main-export)])
#'(module runtime-wrapper racket/base
(module POLLEN-MOD-NAME pollen
[DOC (setup:main-export)]
[PARSER-MODE-FROM-READER parser-mode-from-reader]
[POLLEN-MODULE-SYNTAX (let ([mod-stx #'(module POLLEN-MOD-NAME pollen
(define-meta HERE-KEY HERE-PATH)
(define parser-mode 'PARSER-MODE-VALUE)
(provide (except-out (all-defined-out) parser-mode)
(prefix-out inner: parser-mode)) ; avoids conflicts with importing modules
(provide (all-defined-out))
DIRECTORY-REQUIRES
. SOURCE-LINES)
. SOURCE-LINES)])
(syntax-property mod-stx 'parser-mode-from-reader parser-mode-from-reader))])
#'(module runtime-wrapper racket/base
POLLEN-MODULE-SYNTAX
(require (submod pollen/private/runtime-config show) 'POLLEN-MOD-NAME)
(provide (all-from-out 'POLLEN-MOD-NAME))
(show DOC inner:parser-mode HERE-PATH))))) ; HERE-PATH acts as "local" runtime config
(show DOC 'PARSER-MODE-FROM-READER HERE-PATH))))) ; HERE-PATH acts as "local" runtime config
(syntax-property parsed-syntax
'module-language
`#(pollen/private/language-info get-language-info ,reader-here-path))) ; reader-here-path acts as "top" runtime config

@ -1 +1 @@
1462218309
1462223092

Loading…
Cancel
Save