From 5884bb1a494854431cb7f083f30c97b3336fa65b Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 20 Aug 2015 07:17:50 -0700 Subject: [PATCH] small clarifications; add `here-key-path` --- doclang-raw.rkt | 2 +- reader-base.rkt | 16 +++++++++------- scribblings/world.scrbl | 4 +++- template.rkt | 2 +- world.rkt | 4 +++- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/doclang-raw.rkt b/doclang-raw.rkt index 97ec97a..b4f203b 100755 --- a/doclang-raw.rkt +++ b/doclang-raw.rkt @@ -11,7 +11,7 @@ (define-syntax (*module-begin stx) (syntax-case stx () [(_ . body) - (with-syntax ([id #'doc-raw] + (with-syntax ([id #'doc-raw] ; name of the main export from doclang-raw [post-process #'(λ(x) x)] [exprs #'()]) #'(#%module-begin diff --git a/reader-base.rkt b/reader-base.rkt index 846ff6c..acd3fad 100644 --- a/reader-base.rkt +++ b/reader-base.rkt @@ -9,7 +9,8 @@ (define (split-metas tree) - (define (meta-matcher x) (and (pair? x) (eq? (car x) (world:current-define-meta-name)))) + (define (meta-matcher x) ; meta has form (define-meta key value) + (and (list? x) (>= (length x) 3) (eq? (first x) (world:current-define-meta-name)))) (define matches empty) (define rest (let loop ([x tree]) @@ -22,7 +23,8 @@ (set! matches (append new-matches matches)) (map loop rest)] [else x]))) - (values matches rest)) + (let ([meta-key second][meta-value third]) + (values (map meta-key matches) (map meta-value matches) rest))) (define (make-custom-read-syntax reader-mode) @@ -36,7 +38,7 @@ #:syntax? #t #:inside? #t)) (define source-stx (read-inner path-string p)) - (define-values (meta-matches meta-free-file-data) (split-metas (syntax->datum source-stx))) + (define-values (meta-keys meta-values meta-free-file-data) (split-metas (syntax->datum source-stx))) (define reader-here-path (cond [(symbol? path-string) (symbol->string path-string)] [(equal? path-string "unsaved editor") path-string] @@ -51,10 +53,10 @@ [else world:mode-preproc])]) auto-computed-mode) reader-mode)) - (define meta-keys (cons 'here-path (map second meta-matches))) - (define meta-values (cons reader-here-path (map third meta-matches))) - (with-syntax ([(KEY ...) (datum->syntax source-stx meta-keys)] - [(VALUE ...) (datum->syntax source-stx meta-values)]) + (define meta-keys-plus-here (cons (world:current-here-path-key) meta-keys)) ; here-path at front so it can be overridden + (define meta-values-plus-here (cons reader-here-path meta-values)) + (with-syntax ([(KEY ...) (datum->syntax source-stx meta-keys-plus-here)] + [(VALUE ...) (datum->syntax source-stx meta-values-plus-here)]) (syntax-property (replace-context source-stx #`(module runtime-wrapper racket/base diff --git a/scribblings/world.scrbl b/scribblings/world.scrbl index b800d35..4e7e543 100644 --- a/scribblings/world.scrbl +++ b/scribblings/world.scrbl @@ -131,4 +131,6 @@ Default separators used in decoding. The first two are initialized to @racket["\ @defoverridable[compile-cache-max-size exact-positive-integer?]{Maximum size of the compile cache. Default is 10 megabytes.} -@defoverridable[unpublished-path? (path? . -> . boolean?)]{Predicate that determines whether a path is omitted from @secref{raco_pollen_publish} operations. If the predicate is @racket[#t], then the path is omitted. The default, therefore, is @racket[#f].} \ No newline at end of file +@defoverridable[unpublished-path? (path? . -> . boolean?)]{Predicate that determines whether a path is omitted from @secref{raco_pollen_publish} operations. If the predicate is @racket[#t], then the path is omitted. The default, therefore, is @racket[#f].} + +@defoverridable[here-path-key symbol?]{Key used to store the absolute path of the current source file in its @racket[metas] hashtable. Default is @racket['here-path].} \ No newline at end of file diff --git a/template.rkt b/template.rkt index ef04dcd..d75f8d4 100644 --- a/template.rkt +++ b/template.rkt @@ -8,7 +8,7 @@ (define/contract+provide (metas->here metas) (hash? . -> . pagenode?) - (path->pagenode (or (select-from-metas 'here-path metas) 'unknown))) + (path->pagenode (or (select-from-metas (world:current-here-path-key) metas) 'unknown))) (define (pagenode->path pagenode) diff --git a/world.rkt b/world.rkt index 72ec08f..d310476 100644 --- a/world.rkt +++ b/world.rkt @@ -89,4 +89,6 @@ (define-settable compile-cache-active #t) (define-settable compile-cache-max-size (* 10 1024 1024)) ; = 10 megabytes -(define-settable unpublished-path? (λ(path) #f)) \ No newline at end of file +(define-settable unpublished-path? (λ(path) #f)) + +(define-settable here-path-key 'here-path) \ No newline at end of file