simplify reader modules; put reader-modes in world

pull/9/head
Matthew Butterick 11 years ago
parent 14542cc2a6
commit 6a25de6462

@ -152,7 +152,7 @@
(define+provide/contract (decoder-source? x)
(any/c . -> . coerce/boolean?)
(and (pathish? x) ((->path x) . has-ext? . DECODER_SOURCE_EXT)))
(and (pathish? x) ((->path x) . has-ext? . MARKUP_SOURCE_EXT)))
(define+provide/contract (null-source? x)
@ -196,7 +196,7 @@
(coerce/path? . -> . coerce/path?)
(if (decoder-source? x)
x
(add-ext x DECODER_SOURCE_EXT)))
(add-ext x MARKUP_SOURCE_EXT)))
(define+provide/contract (project-files-with-ext ext)

@ -2,7 +2,7 @@
(require (only-in scribble/reader make-at-reader)
pollen/world)
(provide (all-defined-out))
(provide (all-defined-out) (all-from-out pollen/world))
(define read-inner
(make-at-reader #:command-char EXPRESSION_DELIMITER #:syntax? #t #:inside? #t))
@ -20,3 +20,10 @@
(define reader-mode ',reader-mode)
,@file-contents)
file-contents)))
(define-syntax-rule (make-reader-with-mode mode)
(begin
(define reader-mode mode)
(define pollen-read-syntax (make-pollen-read-syntax reader-mode))
(define pollen-read (make-pollen-read pollen-read-syntax))
(provide (rename-out [pollen-read read] [pollen-read-syntax read-syntax]) read-inner)))

@ -1,9 +1,4 @@
#lang racket/base
(require pollen/lang/reader-base)
(provide (rename-out [pollen-read read] [pollen-read-syntax read-syntax]) read-inner)
(define reader-mode 'auto)
(define pollen-read-syntax (make-pollen-read-syntax reader-mode))
(define pollen-read (make-pollen-read pollen-read-syntax))
(make-reader-with-mode reader-mode-auto)

@ -60,17 +60,17 @@
;; set the parser mode based on reader mode
(define parser-mode
(if (reader-mode . equal? . 'auto)
(if (reader-mode . equal? . reader-mode-auto)
(let* ([file-ext-pattern (pregexp "\\w+$")]
[here-ext (car (regexp-match file-ext-pattern inner-here-path))])
(cond
[(equal? here-ext (symbol->string PTREE_SOURCE_EXT)) 'ptree]
[(equal? here-ext (symbol->string DECODER_SOURCE_EXT)) 'markup]
[(equal? (string->symbol here-ext) PTREE_SOURCE_EXT) reader-mode-ptree]
[(equal? (string->symbol here-ext) MARKUP_SOURCE_EXT) reader-mode-markup]
[else 'pre]))
reader-mode))
(define main (apply (cond
[(equal? parser-mode 'ptree)
[(equal? parser-mode reader-mode-ptree)
(λ xs (decode (cons PTREE_ROOT_NODE xs)
#:xexpr-elements-proc (λ(xs) (filter (compose1 not (def/c whitespace?)) xs))))]
;; 'root is the hook for the decoder function.
@ -87,6 +87,6 @@
;; for output in DrRacket
(module+ main
(if (equal? parser-mode 'pre)
(if (equal? parser-mode reader-mode-preproc)
(display main)
(print main)))))

@ -1,9 +1,4 @@
#lang racket/base
(require pollen/lang/reader-base)
(provide (rename-out [pollen-read read] [pollen-read-syntax read-syntax]) read-inner)
(define reader-mode 'markup)
(define pollen-read-syntax (make-pollen-read-syntax reader-mode))
(define pollen-read (make-pollen-read pollen-read-syntax))
(make-reader-with-mode reader-mode-markup)

@ -1,9 +1,4 @@
#lang racket/base
(require pollen/lang/reader-base)
(provide (rename-out [pollen-read read] [pollen-read-syntax read-syntax]) read-inner)
(define reader-mode 'pre)
(define pollen-read-syntax (make-pollen-read-syntax reader-mode))
(define pollen-read (make-pollen-read pollen-read-syntax))
(make-reader-with-mode reader-mode-preproc)

@ -51,7 +51,7 @@
(define+provide/contract (directory->ptree dir)
(directory-pathish? . -> . ptree?)
(let ([files (map remove-ext (filter (λ(x) (has-ext? x DECODER_SOURCE_EXT)) (directory-list dir)))])
(let ([files (map remove-ext (filter (λ(x) (has-ext? x MARKUP_SOURCE_EXT)) (directory-list dir)))])
(ptree-root->ptree (cons PTREE_ROOT_NODE files))))
;; Try loading from ptree file, or failing that, synthesize ptree.

@ -1,9 +1,4 @@
#lang racket/base
(require pollen/lang/reader-base)
(provide (rename-out [pollen-read read] [pollen-read-syntax read-syntax]) read-inner)
(define reader-mode 'ptree)
(define pollen-read-syntax (make-pollen-read-syntax reader-mode))
(define pollen-read (make-pollen-read pollen-read-syntax))
(make-reader-with-mode reader-mode-ptree)

@ -7,10 +7,10 @@
(define POLLEN_VERSION "0.001")
(define PREPROC_SOURCE_EXT 'p)
(define DECODER_SOURCE_EXT 'pm)
(define MARKUP_SOURCE_EXT 'pm)
(define NULL_SOURCE_EXT 'px)
(define PTREE_SOURCE_EXT 'ptree)
(define DECODABLE_EXTENSIONS (list DECODER_SOURCE_EXT PTREE_SOURCE_EXT))
(define DECODABLE_EXTENSIONS (list MARKUP_SOURCE_EXT PTREE_SOURCE_EXT))
(define DEFAULT_PTREE "main.ptree")
(define PTREE_ROOT_NODE 'ptree-root)
@ -55,4 +55,10 @@
(define DASHBOARD_CSS "poldash.css")
(define current-module-root (make-parameter #f))
(define current-server-extras-path (make-parameter #f))
(define current-server-extras-path (make-parameter #f))
(define reader-mode-auto 'auto)
(define reader-mode-preproc 'pre)
(define reader-mode-markup 'markup)
(define reader-mode-ptree 'ptree)

Loading…
Cancel
Save