File: shadow-script.rkt

package info (click to toggle)
racket 7.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 125,432 kB
  • sloc: ansic: 258,980; pascal: 59,975; sh: 33,650; asm: 13,558; lisp: 7,124; makefile: 3,329; cpp: 2,889; exp: 499; python: 274; xml: 11
file content (60 lines) | stat: -rw-r--r-- 1,574 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#lang at-exp racket/base
(require racket/dict
         racket/format
         racket/string
         "base.rkt")

(provide make-shadow-script)

(define shadow-prefix "shadow:")

(define (make-header f)
@string-append{
#lang racket/base
(require quickscript
         (prefix-in @shadow-prefix (file @(~s (path->string f)))))

 })

;; todo: change properties only if not default?
(define (shadow-script-proc fun-sym props)
  (define (dstr sym)
    (~s (dict-ref props sym)))
  (define fun-str (symbol->string fun-sym))
@string-append{
(define-script @fun-str
  #:label @(dstr 'label)
  #:menu-path @(dstr 'menu-path)
  #:shortcut @(dstr 'shortcut)
  #:shortcut-prefix @(dstr 'shortcut-prefix)
  #:output-to @(dstr 'output-to)
  @(if (dict-ref props 'persistent?)
        "#:persistent"
        "")
  @|shadow-prefix|@fun-str)
  
}
)

(define (make-shadow-script f)
  (parameterize ([current-namespace (make-base-empty-namespace)])
    (define props-dict (get-property-dicts f))
    (define funs (dict-keys props-dict))
    (string-append
     (make-header f)
     "\n"
     (string-join
      (for/list ([(fun props) (in-dict props-dict)])
        (shadow-script-proc fun props))
      "\n"))))


(module+ main
  (require syntax/modresolve
           racket/path)
  ; don't bother if the module does not exist.
  (with-handlers ([exn:fail:filesystem:missing-module? void])
    (define qs-path (resolve-module-path 'quickscript-extra))
    (define f (build-path (path-only qs-path)
                          "scripts" "bookmarks.rkt"))
    (displayln (make-shadow-script f))))