add persistent pattern caches
parent
a31e5b0d79
commit
5de6888d42
@ -1,17 +1,31 @@
|
||||
#lang racket/base
|
||||
(require hyphenate/private/core racket/list racket/file)
|
||||
(provide (rename-out [pmb #%module-begin]) #%app #%datum #%top-interaction)
|
||||
|
||||
(module reader racket/base
|
||||
(require racket/port syntax/strip-context)
|
||||
(provide (rename-out [pattern-prep-read read]
|
||||
[pattern-prep-read-syntax read-syntax]))
|
||||
|
||||
(define (pattern-prep-read in)
|
||||
(syntax->datum (pattern-prep-read-syntax #f in)))
|
||||
(define-syntax-rule (pmb SRC STRS)
|
||||
(#%module-begin
|
||||
(provide patterns)
|
||||
(define strs (list . STRS))
|
||||
(define src SRC)
|
||||
(define-values (dir name _) (split-path src))
|
||||
(define pattern-cache-path (build-path dir "compiled" "pattern-cache.rktd"))
|
||||
(unless (and (file-exists? pattern-cache-path)
|
||||
(> (file-or-directory-modify-seconds pattern-cache-path)
|
||||
(file-or-directory-modify-seconds src)))
|
||||
(define patterns (for/hasheq ([str (in-list strs)])
|
||||
(define strkey+val (string->hashpair str))
|
||||
(values (string->symbol (first strkey+val)) (second strkey+val))))
|
||||
(write-to-file patterns pattern-cache-path #:exists 'replace))
|
||||
(define patterns (file->value pattern-cache-path))))
|
||||
|
||||
(module+ reader
|
||||
(provide read-syntax)
|
||||
|
||||
(define (pattern-prep-read-syntax src in)
|
||||
(with-syntax ([str (port->string in)])
|
||||
(strip-context
|
||||
#'(module pattern-prep racket/base
|
||||
(require hyphenate/private/core racket/list racket/string)
|
||||
(provide patterns)
|
||||
(define patterns (apply hash (append-map string->hashpair (string-split str)))))))))
|
||||
(define (read-syntax src in)
|
||||
(with-syntax ([SRC (path->string src)]
|
||||
[STRS (for/list ([line (in-lines in)]
|
||||
#:when (and (positive? (string-length line)) ; omit empty
|
||||
(not (regexp-match #rx"^;" line)))) ; omit comments
|
||||
line)])
|
||||
(syntax->datum #'(module patterns hyphenate/private/pattern-prep
|
||||
SRC STRS)))))
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue