tidier patch #170

Merged
mbutterick merged 1 commits from tidier-patch into master 7 years ago

@ -1,4 +1,4 @@
#lang s-exp "private/main-base.rkt" #lang s-exp pollen/private/dialect
default-mode-preproc default-mode-preproc
(module reader "private/reader-base.rkt" (module reader "private/reader-base.rkt"

@ -1,4 +1,4 @@
#lang s-exp "private/main-base.rkt" #lang s-exp pollen/private/dialect
default-mode-markdown default-mode-markdown
(module reader "private/reader-base.rkt" (module reader "private/reader-base.rkt"

@ -1,4 +1,4 @@
#lang s-exp "private/main-base.rkt" #lang s-exp pollen/private/dialect
default-mode-markup default-mode-markup
(module reader "private/reader-base.rkt" (module reader "private/reader-base.rkt"

@ -1,4 +1,4 @@
#lang s-exp "private/main-base.rkt" #lang s-exp pollen/private/dialect
default-mode-preproc default-mode-preproc
(module reader "private/reader-base.rkt" (module reader "private/reader-base.rkt"

@ -0,0 +1,12 @@
#lang racket/base
(require pollen/setup)
(provide (except-out (all-from-out racket/base pollen/setup) #%module-begin)
(rename-out [mb #%module-begin]) #%top-interaction)
(define-syntax-rule (mb mode . args)
(#%module-begin
(require (prefix-in p: "private/main-base.rkt"))
(provide (rename-out [mb #%module-begin]))
(define-syntax-rule (mb . other-args)
(p:#%module-begin mode . other-args))
. args))

@ -1,26 +1,9 @@
#lang racket/base #lang racket/base
(require (for-syntax racket/base racket/syntax syntax/strip-context "../setup.rkt" "split-metas.rkt") (require (for-syntax racket/base syntax/strip-context "../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")) (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 [pollen-module-begin #%module-begin]))
;; 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))) (define (stringify xs) (apply string-append (map to-string xs)))
@ -40,14 +23,11 @@
(or (memf (λ (ln) (and (not (equal? ln (setup:newline))) (or (memf (λ (ln) (and (not (equal? ln (setup:newline)))
(not (equal? ln "")))) doc) null)) (not (equal? ln "")))) doc) null))
(define-syntax (pollen-module-begin stx) (define-syntax (pollen-module-begin stx)
(syntax-case stx () (syntax-case stx ()
[(_ . EXPRS) [(_ PARSER-MODE . EXPRS)
(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
[EXPRS (replace-context #'here #'EXPRS)] [EXPRS (replace-context #'here #'EXPRS)]
[PARSER-MODE-FROM-READER (syntax-property stx 'parser-mode-from-reader)]
[PARSER-MODE-FROM-EXPANDER (syntax-property #'EXPRS 'parser-mode-from-expander)]
[META-HASH (split-metas #'EXPRS (setup:define-meta-name))] [META-HASH (split-metas #'EXPRS (setup:define-meta-name))]
[METAS-ID (setup:meta-export)] [METAS-ID (setup:meta-export)]
[META-MOD-ID (setup:meta-export)] [META-MOD-ID (setup:meta-export)]
@ -56,8 +36,7 @@
#'(doclang:#%module-begin #'(doclang:#%module-begin
DOC-ID ; positional arg for doclang-raw: name of export DOC-ID ; positional arg for doclang-raw: name of export
(λ (xs) (λ (xs)
(define parser-mode (or 'PARSER-MODE-FROM-READER PARSER-MODE-FROM-EXPANDER)) (define proc (make-parse-proc PARSER-MODE ROOT-ID))
(define proc (make-parse-proc parser-mode ROOT-ID))
(define doc-elements (splice (strip-leading-newlines xs) (setup:splicing-tag))) (define doc-elements (splice (strip-leading-newlines xs) (setup:splicing-tag)))
(proc doc-elements)) ; positional arg for doclang-raw: post-processor (proc doc-elements)) ; positional arg for doclang-raw: post-processor
(module META-MOD-ID racket/base (module META-MOD-ID racket/base

@ -22,6 +22,10 @@
auto-computed-mode) auto-computed-mode)
reader-mode)) reader-mode))
(define (derive-expander-name mode)
(define suffix (if (eq? mode default-mode-auto) "" mode))
(string->symbol (format "pollen/~a" suffix)))
(define (custom-read p) (define (custom-read p)
(syntax->datum (custom-read-syntax (object-name p) p))) (syntax->datum (custom-read-syntax (object-name p) p)))
@ -36,36 +40,28 @@
(define parser-mode-from-reader (infer-parser-mode reader-mode reader-here-path)) (define parser-mode-from-reader (infer-parser-mode reader-mode reader-here-path))
(strip-context (strip-context
(with-syntax* ([POLLEN-MOD-NAME 'pollen-module] (with-syntax* ([POLLEN-MOD-NAME 'pollen-module]
;; these exist only in the reader because they are specific to file-based Pollen sources. ;; the next two exist only in the reader because they are specific to file-based Pollen sources.
;; an inline Pollen submodule doesn't have "pollen.rkt" or `here-path` ;; an inline Pollen submodule doesn't have "pollen.rkt" or `here-path`
[POLLEN-REQUIRE-AND-PROVIDES (require+provide-directory-require-files path-string)] [POLLEN-REQUIRE-AND-PROVIDES (require+provide-directory-require-files path-string)]
[HERE-KEY (setup:here-path-key)]
[HERE-PATH reader-here-path] [HERE-PATH reader-here-path]
[HERE-KEY (setup:here-path-key)]
[SOURCE-LINES source-stx] [SOURCE-LINES source-stx]
[DOC (setup:main-export)] [DOC (setup:main-export)]
[META-MOD (setup:meta-export)] [META-MOD (setup:meta-export)]
[PARSER-MODE-FROM-READER parser-mode-from-reader] [METAS-ID (setup:meta-export)]
[EXPANDER (cond [PARSER-MODE-FROM-READER parser-mode-from-reader])
[(eq? parser-mode-from-reader default-mode-markup) 'pollen/markup]
[(eq? parser-mode-from-reader default-mode-markdown) 'pollen/markdown]
[(eq? parser-mode-from-reader default-mode-pagetree) 'pollen/ptree]
[(eq? parser-mode-from-reader default-mode-preproc) 'pollen/pre]
[(eq? parser-mode-from-reader default-mode-auto) 'pollen]
[(eq? parser-mode-from-reader default-mode-template) 'pollen/template]
[else 'pollen])]
[POLLEN-MODULE-SYNTAX (let ([mod-stx #'(module POLLEN-MOD-NAME EXPANDER
(define-meta HERE-KEY HERE-PATH)
POLLEN-REQUIRE-AND-PROVIDES
. SOURCE-LINES)])
(syntax-property mod-stx 'parser-mode-from-reader parser-mode-from-reader))])
#'(module runtime-wrapper racket/base #'(module runtime-wrapper racket/base
(module configure-runtime racket/base (module configure-runtime racket/base
(require pollen/private/runtime-config) (require pollen/private/runtime-config)
(configure HERE-PATH)) ; HERE-PATH acts as "top" runtime config when module is main (configure HERE-PATH)) ; HERE-PATH acts as "top" runtime config when module is main
POLLEN-MODULE-SYNTAX (module POLLEN-MOD-NAME pollen/private/main-base
'PARSER-MODE-FROM-READER
(define-meta HERE-KEY HERE-PATH)
POLLEN-REQUIRE-AND-PROVIDES
. SOURCE-LINES)
(module META-MOD racket/base (module META-MOD racket/base
(require (submod ".." POLLEN-MOD-NAME META-MOD)) (require (submod ".." POLLEN-MOD-NAME META-MOD))
(provide (all-from-out (submod ".." POLLEN-MOD-NAME META-MOD)))) (provide METAS-ID))
(require (only-in pollen/private/runtime-config show) 'POLLEN-MOD-NAME) (require (only-in pollen/private/runtime-config show) 'POLLEN-MOD-NAME)
(provide (all-from-out 'POLLEN-MOD-NAME)) (provide (all-from-out 'POLLEN-MOD-NAME))
(show DOC 'PARSER-MODE-FROM-READER HERE-PATH))))) ; HERE-PATH otherwise acts as "local" runtime config (show DOC 'PARSER-MODE-FROM-READER HERE-PATH))))) ; HERE-PATH otherwise acts as "local" runtime config
@ -98,7 +94,7 @@
(dynamic-require 'scribble/private/indentation 'determine-spaces)] (dynamic-require 'scribble/private/indentation 'determine-spaces)]
[else default])))) [else default]))))
(define-syntax-rule (reader-module-begin mode expr-to-ignore ...) (define-syntax-rule (reader-module-begin mode . _)
(#%module-begin (#%module-begin
(define cgi custom-get-info) ; stash hygienic references to local funcs with macro-introduced identifiers (define cgi custom-get-info) ; stash hygienic references to local funcs with macro-introduced identifiers
(define cr custom-read) ; so they can be provided out (define cr custom-read) ; so they can be provided out

@ -1,4 +1,4 @@
#lang s-exp "private/main-base.rkt" #lang s-exp pollen/private/dialect
default-mode-pagetree default-mode-pagetree
(module reader "private/reader-base.rkt" (module reader "private/reader-base.rkt"

Loading…
Cancel
Save