|
|
@ -4,9 +4,25 @@
|
|
|
|
(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]))
|
|
|
|
|
|
|
|
|
|
|
|
(define (stringify xs) (apply string-append (map to-string xs)))
|
|
|
|
;; PARSER-MODE-FROM-READER is used when Pollen is invoked as a specific dialect #lang, and the expander is the generic `pollen/main`.
|
|
|
|
|
|
|
|
;; PARSER-MODE-FROM-EXPANDER is used when Pollen is invoked through an inline submodule,
|
|
|
|
|
|
|
|
;; and the expander is a specific dialect: `pollen/markup`, `pollen/pre`, etc.
|
|
|
|
|
|
|
|
;; they only differ in the `pollen/main` dialect, where the reader infers the dialect from the file extension.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (dialect-module-begin PARSER-MODE-FROM-EXPANDER READER-SUBMOD)
|
|
|
|
|
|
|
|
(#%module-begin
|
|
|
|
|
|
|
|
(require racket/base)
|
|
|
|
|
|
|
|
(provide (except-out (all-from-out racket/base) #%module-begin)
|
|
|
|
|
|
|
|
(rename-out [pmb #%module-begin]))
|
|
|
|
|
|
|
|
(define-syntax (pmb stx)
|
|
|
|
|
|
|
|
(syntax-case stx ()
|
|
|
|
|
|
|
|
[(_ . EXPRS) (with-syntax ([EXPRS (syntax-property #'EXPRS 'parser-mode-from-expander 'PARSER-MODE-FROM-EXPANDER)])
|
|
|
|
|
|
|
|
#'(pollen-module-begin . EXPRS))]))
|
|
|
|
|
|
|
|
READER-SUBMOD))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-parse-proc parser-mode root-proc)
|
|
|
|
(define (make-parse-proc parser-mode root-proc)
|
|
|
|
|
|
|
|
(define (stringify xs) (apply string-append (map to-string xs)))
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
[(eq? parser-mode default-mode-pagetree) decode-pagetree]
|
|
|
|
[(eq? parser-mode default-mode-pagetree) decode-pagetree]
|
|
|
|
[(eq? parser-mode default-mode-markup) (λ (xs) (apply root-proc (remove-voids xs)))]
|
|
|
|
[(eq? parser-mode default-mode-markup) (λ (xs) (apply root-proc (remove-voids xs)))]
|
|
|
@ -17,18 +33,19 @@
|
|
|
|
(apply root-proc xs)))]
|
|
|
|
(apply root-proc xs)))]
|
|
|
|
[else stringify])) ; preprocessor mode
|
|
|
|
[else stringify])) ; preprocessor mode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (strip-leading-newlines doc)
|
|
|
|
(define (strip-leading-newlines doc)
|
|
|
|
;; 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`
|
|
|
|
(or (memf (λ (ln) (not (equal? ln (setup:newline)))) doc) null))
|
|
|
|
(or (memf (λ (ln) (not (equal? ln (setup:newline)))) doc) null))
|
|
|
|
|
|
|
|
|
|
|
|
(define-for-syntax (make-pmb-macro parser-mode-from-expander)
|
|
|
|
|
|
|
|
(λ (stx)
|
|
|
|
(define-syntax (pollen-module-begin stx)
|
|
|
|
(syntax-case stx ()
|
|
|
|
(syntax-case stx ()
|
|
|
|
[(_ . EXPRS)
|
|
|
|
[(_ . EXPRS)
|
|
|
|
(let-values ([(meta-hash exprs-without-metas) (split-metas (syntax->datum #'EXPRS) (setup:define-meta-name))])
|
|
|
|
(let-values ([(meta-hash exprs-without-metas) (split-metas (syntax->datum #'EXPRS) (setup:define-meta-name))])
|
|
|
|
(with-syntax (;; 'parser-mode-from-reader will be #f for an inline submodule
|
|
|
|
(with-syntax (;; 'parser-mode-from-reader will be #f for an inline submodule
|
|
|
|
[PARSER-MODE-FROM-READER (syntax-property stx 'parser-mode-from-reader)]
|
|
|
|
[PARSER-MODE-FROM-READER (syntax-property stx 'parser-mode-from-reader)]
|
|
|
|
[PARSER-MODE-FROM-EXPANDER parser-mode-from-expander]
|
|
|
|
[PARSER-MODE-FROM-EXPANDER (syntax-property #'EXPRS 'parser-mode-from-expander)]
|
|
|
|
[META-HASH meta-hash]
|
|
|
|
[META-HASH meta-hash]
|
|
|
|
[EXPRS-WITHOUT-METAS exprs-without-metas]
|
|
|
|
[EXPRS-WITHOUT-METAS exprs-without-metas]
|
|
|
|
[METAS-ID (setup:meta-export)]
|
|
|
|
[METAS-ID (setup:meta-export)]
|
|
|
@ -60,13 +77,4 @@
|
|
|
|
[doc-elements-spliced (splice doc-elements (setup:splicing-tag))])
|
|
|
|
[doc-elements-spliced (splice doc-elements (setup:splicing-tag))])
|
|
|
|
(proc doc-elements-spliced)))
|
|
|
|
(proc doc-elements-spliced)))
|
|
|
|
|
|
|
|
|
|
|
|
(provide DOC-ID METAS-ID (except-out (all-from-out 'inner) DOC-RAW)))))])))
|
|
|
|
(provide DOC-ID METAS-ID (except-out (all-from-out 'inner) DOC-RAW)))))]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(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)
|
|
|
|
|
|
|
|
(rename-out [pollen-module-begin #%module-begin]))
|
|
|
|
|
|
|
|
(define-syntax pollen-module-begin (make-pmb-macro 'PARSER-MODE-FROM-EXPANDER))
|
|
|
|
|
|
|
|
. READER-SUBMOD-AND-OTHER-EXPRS))
|
|
|
|
|
|
|
|