|
|
@ -1,29 +1,17 @@
|
|
|
|
#lang racket/base
|
|
|
|
#lang racket/base
|
|
|
|
(require racket/syntax syntax/strip-context racket/class)
|
|
|
|
(require racket/syntax syntax/strip-context racket/class (for-syntax racket/base))
|
|
|
|
(require (only-in scribble/reader make-at-reader) pollen/setup "project.rkt" racket/list)
|
|
|
|
(require (only-in scribble/reader make-at-reader) "../setup.rkt" "project.rkt")
|
|
|
|
(provide define+provide-reader-in-mode (all-from-out pollen/setup))
|
|
|
|
(provide (rename-out [reader-module-begin #%module-begin]) (all-from-out "../setup.rkt"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (path-string->here-path path-string)
|
|
|
|
(define (make-custom-read custom-read-syntax-proc)
|
|
|
|
(cond
|
|
|
|
(λ(p) (syntax->datum (custom-read-syntax-proc (object-name p) p))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-custom-read-syntax reader-mode)
|
|
|
|
|
|
|
|
(λ (path-string p)
|
|
|
|
|
|
|
|
(define read-inner (make-at-reader
|
|
|
|
|
|
|
|
#:command-char (if (or (eq? reader-mode default-mode-template)
|
|
|
|
|
|
|
|
(and (string? path-string)
|
|
|
|
|
|
|
|
(regexp-match (pregexp (format "\\.~a$" (setup:template-source-ext))) path-string)))
|
|
|
|
|
|
|
|
(setup:template-command-char)
|
|
|
|
|
|
|
|
(setup:command-char))
|
|
|
|
|
|
|
|
#:syntax? #t
|
|
|
|
|
|
|
|
#:inside? #t))
|
|
|
|
|
|
|
|
(define source-stx (read-inner path-string p))
|
|
|
|
|
|
|
|
(define reader-here-path (cond
|
|
|
|
|
|
|
|
[(symbol? path-string) (symbol->string path-string)]
|
|
|
|
[(symbol? path-string) (symbol->string path-string)]
|
|
|
|
[(equal? path-string "unsaved editor") path-string]
|
|
|
|
[(equal? path-string "unsaved editor") path-string]
|
|
|
|
[else (path->string path-string)]))
|
|
|
|
[else (path->string path-string)]))
|
|
|
|
(define parser-mode (if (eq? reader-mode default-mode-auto)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (infer-parser-mode reader-mode reader-here-path)
|
|
|
|
|
|
|
|
(if (eq? reader-mode default-mode-auto)
|
|
|
|
(let* ([file-ext-pattern (pregexp "\\w+$")]
|
|
|
|
(let* ([file-ext-pattern (pregexp "\\w+$")]
|
|
|
|
[here-ext (string->symbol (car (regexp-match file-ext-pattern reader-here-path)))]
|
|
|
|
[here-ext (string->symbol (car (regexp-match file-ext-pattern reader-here-path)))]
|
|
|
|
[auto-computed-mode (cond
|
|
|
|
[auto-computed-mode (cond
|
|
|
@ -33,14 +21,27 @@
|
|
|
|
[else default-mode-preproc])])
|
|
|
|
[else default-mode-preproc])])
|
|
|
|
auto-computed-mode)
|
|
|
|
auto-computed-mode)
|
|
|
|
reader-mode))
|
|
|
|
reader-mode))
|
|
|
|
(define post-parser-syntax
|
|
|
|
|
|
|
|
(with-syntax ([HERE-KEY (format-id source-stx "~a" (setup:here-path-key))]
|
|
|
|
(define (custom-read p)
|
|
|
|
[HERE-PATH (datum->syntax source-stx reader-here-path)]
|
|
|
|
(syntax->datum (custom-read-syntax (object-name p) p)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (custom-read-syntax #:reader-mode [reader-mode #f] path-string p)
|
|
|
|
|
|
|
|
(define source-stx (let ([read-inner (make-at-reader
|
|
|
|
|
|
|
|
#:command-char (setup:command-char)
|
|
|
|
|
|
|
|
#:syntax? #t
|
|
|
|
|
|
|
|
#:inside? #t)])
|
|
|
|
|
|
|
|
(read-inner path-string p)))
|
|
|
|
|
|
|
|
(define reader-here-path (path-string->here-path path-string))
|
|
|
|
|
|
|
|
(define parser-mode (infer-parser-mode reader-mode reader-here-path))
|
|
|
|
|
|
|
|
(define parsed-syntax
|
|
|
|
|
|
|
|
(with-syntax ([HERE-KEY (format-id #f "~a" (setup:here-path-key))]
|
|
|
|
|
|
|
|
[HERE-PATH (datum->syntax #f reader-here-path)]
|
|
|
|
[POLLEN-MOD (format-symbol "~a" (gensym))] ; prevents conflicts with other imported Pollen sources
|
|
|
|
[POLLEN-MOD (format-symbol "~a" (gensym))] ; prevents conflicts with other imported Pollen sources
|
|
|
|
[PARSER-MODE-VALUE (format-symbol "~a" parser-mode)]
|
|
|
|
[PARSER-MODE-VALUE (format-symbol "~a" parser-mode)]
|
|
|
|
[DIRECTORY-REQUIRES (datum->syntax source-stx (require+provide-directory-require-files path-string))]
|
|
|
|
[DIRECTORY-REQUIRES (datum->syntax #f (require+provide-directory-require-files path-string))]
|
|
|
|
[(SOURCE-LINE ...) source-stx]
|
|
|
|
[(SOURCE-LINE ...) source-stx]
|
|
|
|
[DOC (format-id source-stx "~a" (setup:main-export))])
|
|
|
|
[DOC (format-id #f "~a" (setup:main-export))])
|
|
|
|
(replace-context
|
|
|
|
(replace-context
|
|
|
|
source-stx
|
|
|
|
source-stx
|
|
|
|
#'(module runtime-wrapper racket/base
|
|
|
|
#'(module runtime-wrapper racket/base
|
|
|
@ -54,16 +55,11 @@
|
|
|
|
(require (submod pollen/private/runtime-config show) 'POLLEN-MOD)
|
|
|
|
(require (submod pollen/private/runtime-config show) 'POLLEN-MOD)
|
|
|
|
(provide (all-from-out 'POLLEN-MOD))
|
|
|
|
(provide (all-from-out 'POLLEN-MOD))
|
|
|
|
(show DOC inner:parser-mode HERE-PATH))))) ; HERE-PATH acts as "local" runtime config
|
|
|
|
(show DOC inner:parser-mode HERE-PATH))))) ; HERE-PATH acts as "local" runtime config
|
|
|
|
(syntax-property post-parser-syntax
|
|
|
|
(syntax-property parsed-syntax
|
|
|
|
'module-language
|
|
|
|
'module-language
|
|
|
|
`#(pollen/private/language-info get-language-info ,reader-here-path)))) ; reader-here-path acts as "top" runtime config
|
|
|
|
`#(pollen/private/language-info get-language-info ,reader-here-path))) ; reader-here-path acts as "top" runtime config
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (define+provide-reader-in-mode mode)
|
|
|
|
(define (custom-get-info in mod line col pos)
|
|
|
|
(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)
|
|
|
|
|
|
|
|
;; DrRacket caches source file information per session,
|
|
|
|
;; DrRacket caches source file information per session,
|
|
|
|
;; so we can do the same to avoid multiple searches for the command char.
|
|
|
|
;; so we can do the same to avoid multiple searches for the command char.
|
|
|
|
(let ([command-char-cache (make-hash)])
|
|
|
|
(let ([command-char-cache (make-hash)])
|
|
|
@ -88,4 +84,10 @@
|
|
|
|
(define my-make-drracket-buttons (dynamic-require 'pollen/private/drracket-buttons 'make-drracket-buttons))
|
|
|
|
(define my-make-drracket-buttons (dynamic-require 'pollen/private/drracket-buttons 'make-drracket-buttons))
|
|
|
|
(my-make-drracket-buttons my-command-char)])]
|
|
|
|
(my-make-drracket-buttons my-command-char)])]
|
|
|
|
[else default]))))
|
|
|
|
[else default]))))
|
|
|
|
(provide (rename-out [custom-read read] [custom-read-syntax read-syntax]) get-info)))
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (reader-module-begin mode expr-to-ignore ...)
|
|
|
|
|
|
|
|
(#%module-begin
|
|
|
|
|
|
|
|
(define cgi custom-get-info) ; stash hygienic references to local funcs with new identifiers
|
|
|
|
|
|
|
|
(define cr custom-read)
|
|
|
|
|
|
|
|
(define (crs ps p) (custom-read-syntax #:reader-mode mode ps p))
|
|
|
|
|
|
|
|
(provide (rename-out [cr read][crs read-syntax][cgi get-info]))))
|