You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
4.0 KiB
Racket
71 lines
4.0 KiB
Racket
#lang racket/base
|
|
(require (only-in scribble/reader make-at-reader) pollen/world racket/path pollen/project)
|
|
(provide define+provide-reader-in-mode (all-from-out pollen/world))
|
|
|
|
|
|
(define (make-custom-read custom-read-syntax-proc)
|
|
(λ(p) (syntax->datum (custom-read-syntax-proc (object-name p) p))))
|
|
|
|
(require sugar/debug)
|
|
(define (make-custom-read-syntax reader-mode)
|
|
(λ (path-string p)
|
|
(define read-inner (make-at-reader
|
|
#:command-char (if (or (equal? reader-mode world:mode-template)
|
|
(and (string? path-string)
|
|
(regexp-match (pregexp (format "\\.~a$" (world:current-template-source-ext))) path-string)))
|
|
(world:current-template-command-char)
|
|
(world:current-command-char))
|
|
#:syntax? #t
|
|
#:inside? #t))
|
|
(define file-contents (read-inner path-string p))
|
|
(syntax-property
|
|
(datum->syntax file-contents
|
|
`(module runtime-wrapper racket/base
|
|
(module pollen-lang-module pollen
|
|
(define reader-mode ',reader-mode)
|
|
(define reader-here-path ,(cond
|
|
[(symbol? path-string) (symbol->string path-string)]
|
|
[(equal? path-string "unsaved editor") path-string]
|
|
[else (path->string path-string)]))
|
|
(define parser-mode
|
|
(if (equal? reader-mode world:mode-auto)
|
|
(let* ([file-ext-pattern (pregexp "\\w+$")]
|
|
[here-ext (string->symbol (car (regexp-match file-ext-pattern reader-here-path)))])
|
|
(cond
|
|
[(equal? here-ext (world:current-pagetree-source-ext)) world:mode-pagetree]
|
|
[(equal? here-ext (world:current-markup-source-ext)) world:mode-markup]
|
|
[(equal? here-ext (world:current-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-directory-require-files path-string)
|
|
,@file-contents)
|
|
(require (submod pollen/runtime-config show) 'pollen-lang-module)
|
|
(provide (all-from-out 'pollen-lang-module))
|
|
(show ,(world:current-main-export) inner:parser-mode))
|
|
file-contents)
|
|
'module-language
|
|
'#(pollen/language-info get-language-info #f))))
|
|
|
|
|
|
(define-syntax-rule (define+provide-reader-in-mode mode)
|
|
(begin
|
|
(define reader-mode mode)
|
|
(define custom-read-syntax (make-custom-read-syntax reader-mode))
|
|
(define custom-read (make-custom-read custom-read-syntax))
|
|
(define (get-info in mod line col pos)
|
|
(λ (key default)
|
|
(case key
|
|
[(color-lexer)
|
|
(define make-scribble-inside-lexer2
|
|
(dynamic-require 'syntax-color/scribble-lexer 'make-scribble-inside-lexer (λ () #f)))
|
|
(cond [make-scribble-inside-lexer2
|
|
(make-scribble-inside-lexer2 #:command-char #\◊)]
|
|
[else default])]
|
|
[else default])))
|
|
(provide (rename-out [custom-read read] [custom-read-syntax read-syntax]) get-info))) |