preprocessor sorta works

pull/9/head
Matthew Butterick 10 years ago
parent 40f0a70965
commit 84d104f83f

@ -1,15 +1,10 @@
#lang racket/base
(require (only-in scribble/reader make-at-reader)
(only-in "../world.rkt" EXPRESSION_DELIMITER)
(only-in "../file-tools.rkt" decoder-source? ptree-source?))
(require (only-in scribble/reader make-at-reader))
(provide (rename-out [mb-read read]
[mb-read-syntax read-syntax])
read-inner
)
(provide (rename-out [mb-read read] [mb-read-syntax read-syntax]) read-inner)
(define read-inner
(make-at-reader #:command-char EXPRESSION_DELIMITER
(make-at-reader #:command-char #\◊
#:syntax? #t
#:inside? #t))
@ -25,9 +20,5 @@
(define (mb-read-syntax path-string p)
(define i (read-inner path-string p))
(datum->syntax i
;; select pollen dialect based on file type
`(module pollen-lang-module ,(if (or (decoder-source? path-string) (ptree-source? path-string))
'pollen/main
'pollen/main-preproc)
,@i)
`(module pollen-lang-module pollen/main-preproc ,@i)
i))

@ -0,0 +1,36 @@
#lang racket/base
(require "main-preproc-imports.rkt")
(provide (except-out (all-from-out racket/base) #%module-begin)
(rename-out [module-begin #%module-begin]))
(require (only-in scribble/text output)
(only-in racket/list flatten))
(define-syntax-rule (module-begin expr ...)
(#%module-begin
; We want our module language to support require & provide
; which are only supported at the module level, so ...
; create a submodule to contain the input
; and export as needed
; doclang2_raw is a clone of scribble/doclang2 with decode disabled
; helpful because it collects & exports content via 'doc
(module pollen-inner pollen/lang/doclang2_raw
(require pollen/tools pollen/main-helper pollen/top)
(require-and-provide-extras) ; brings in the project require files
expr ...) ; body of module
(require 'pollen-inner) ; provides 'doc
;; reduce text to simplest representation: a single ouput string
(define main (apply string-append (map ->string (flatten (trim (->list doc) whitespace?)))))
(provide main (all-from-out 'pollen-inner))
(module+ main
; (displayln ";-------------------------")
; (displayln (string-append "; pollen 'main"))
; (displayln ";-------------------------")
(display main))))

@ -1,36 +1,21 @@
#lang racket/base
(require "main-preproc-imports.rkt")
(provide (except-out (all-from-out racket/base) #%module-begin)
(rename-out [module-begin #%module-begin]))
(require (only-in scribble/text output)
(only-in racket/list flatten))
(define-syntax-rule (module-begin expr ...)
(#%module-begin
; We want our module language to support require & provide
; which are only supported at the module level, so ...
; create a submodule to contain the input
; and export as needed
; doclang2_raw is a clone of scribble/doclang2 with decode disabled
; helpful because it collects & exports content via 'doc
(module pollen-inner pollen/lang/doclang2_raw
(require pollen/tools pollen/main-helper pollen/top)
(require-and-provide-extras) ; brings in the project require files
(module inner pollen/lang/doclang_raw
main
(λ(x) (apply string-append (cdr x))) ;; chop first linebreak off
()
(provide (all-defined-out))
expr ...) ; body of module
expr ...)
(require 'pollen-inner) ; provides 'doc
(require 'inner)
(provide (all-from-out 'inner))
;; reduce text to simplest representation: a single ouput string
(define main (apply string-append (map ->string (flatten (trim (->list doc) whitespace?)))))
(provide main (all-from-out 'pollen-inner))
(module+ main
; (displayln ";-------------------------")
; (displayln (string-append "; pollen 'main"))
; (displayln ";-------------------------")
(display main))))
Loading…
Cancel
Save