make exports visible as top-level identifiers in REPL

pull/27/head
Matthew Butterick 11 years ago
parent 74ae614b55
commit e311d4e362

@ -34,25 +34,14 @@
(require 'inner) (require 'inner)
;; if reader-here-path is undefined, it will become a proc courtesy of #%top ;; in an inline module, reader-here-path and parser-mode are undefined
;; therefore that's how we can detect if it's undefined ;; (because there's no reader)
(define here-path (if (procedure? inner:reader-here-path) "anonymous-module" inner:reader-here-path)) ;; but they'll become tag functions courtesy of #%top
;; so that's how we can detect if they are undefined
(define here-path
;; set the parser mode based on reader mode (if (procedure? inner:reader-here-path) "anonymous-module" inner:reader-here-path))
;; todo: this won't work with inline submodules
(define parser-mode (define parser-mode
(if (not (procedure? inner:reader-mode)) (if (procedure? inner:parser-mode) mode-arg inner:parser-mode))
(if (equal? inner:reader-mode world:mode-auto)
(let* ([file-ext-pattern (pregexp "\\w+$")]
[here-ext (string->symbol (car (regexp-match file-ext-pattern here-path)))])
(cond
[(equal? here-ext world:pagetree-source-ext) world:mode-pagetree]
[(equal? here-ext world:markup-source-ext) world:mode-markup]
[(equal? here-ext world:markdown-source-ext) world:mode-markdown]
[else world:mode-preproc]))
inner:reader-mode)
mode-arg))
;; Split out the metas. ;; Split out the metas.
@ -106,10 +95,4 @@
(provide metas doc (provide metas doc
;; hide the exports that were only for internal use. ;; hide the exports that were only for internal use.
(except-out (all-from-out 'inner) doc-raw #%top)) (except-out (all-from-out 'inner) doc-raw #%top))))]))))]))
;; for output in DrRacket
(module+ main
(if (or (equal? parser-mode world:mode-preproc) (equal? parser-mode world:mode-template))
(display doc)
(print doc)))))]))))]))

@ -14,28 +14,46 @@
(λ (path-string p) (λ (path-string p)
(define read-inner (make-at-reader (define read-inner (make-at-reader
#:command-char (if (or (equal? reader-mode world:mode-template) #:command-char (if (or (equal? reader-mode world:mode-template)
(and (string? path-string) (regexp-match (pregexp (format "\\.~a$" world:template-source-ext)) path-string))) (and (string? path-string) (regexp-match (pregexp (format "\\.~a$" world:template-source-ext)) path-string)))
world:template-command-marker world:template-command-marker
world:command-marker) world:command-marker)
#:syntax? #t #:syntax? #t
#:inside? #t)) #:inside? #t))
(define file-contents (read-inner path-string p)) (define file-contents (read-inner path-string p))
(datum->syntax file-contents (datum->syntax file-contents
`(module pollen-lang-module pollen `(module repl-wrapper racket/base
(define reader-mode ',reader-mode) (module pollen-lang-module pollen
(define reader-here-path ,(cond (define reader-mode ',reader-mode)
[(symbol? path-string) (symbol->string path-string)] (define reader-here-path ,(cond
[(equal? path-string "unsaved editor") path-string] [(symbol? path-string) (symbol->string path-string)]
[else (path->string path-string)])) [(equal? path-string "unsaved editor") path-string]
;; change the name of reader-here-path & reader-mode for local use [else (path->string path-string)]))
;; so they don't conflict if this source is imported into another (define parser-mode
(provide (except-out (all-defined-out) reader-here-path reader-mode) (if (equal? reader-mode world:mode-auto)
(prefix-out inner: reader-here-path) (let* ([file-ext-pattern (pregexp "\\w+$")]
(prefix-out inner: reader-mode)) [here-ext (string->symbol (car (regexp-match file-ext-pattern reader-here-path)))])
(cond
,(require+provide-project-require-files path-string) [(equal? here-ext world:pagetree-source-ext) world:mode-pagetree]
,@file-contents) [(equal? here-ext world:markup-source-ext) world:mode-markup]
file-contents))) [(equal? here-ext world:markdown-source-ext) world:mode-markdown]
[else world:mode-preproc]))
reader-mode))
;; change names of exports for local use
;; so they don't conflict if this source is imported into another
(provide (except-out (all-defined-out) reader-here-path reader-mode parser-mode)
(prefix-out inner: reader-here-path)
(prefix-out inner: reader-mode)
(prefix-out inner: parser-mode))
,(require+provide-project-require-files path-string)
,@file-contents)
(require 'pollen-lang-module)
(provide (all-from-out 'pollen-lang-module))
(module+ main
(if (or (equal? inner:parser-mode world:mode-preproc) (equal? inner:parser-mode world:mode-template))
(display doc)
(print doc))))
file-contents)))
(define-syntax-rule (define+provide-reader-in-mode mode) (define-syntax-rule (define+provide-reader-in-mode mode)

Loading…
Cancel
Save