/usr/share/racket/collects/syntax/modresolve.rkt is in racket-common 6.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | #lang racket/base
(require racket/contract/base
"private/modhelp.rkt")
(define (force-relto relto dir? #:path? [path? #t])
(let ([relto (if (and (pair? relto)
(eq? (car relto) 'submod))
(cadr relto)
relto)]
[submod (if (and (pair? relto)
(eq? (car relto) 'submod))
(cddr relto)
null)])
(cond [(path-string? relto)
(values (and path?
(if dir?
(let-values ([(base n d?) (split-path relto)])
(when d?
(error 'resolve-module-path-index
"given a directory path instead of a file path: ~e" relto))
(if (eq? base 'relative)
(or (current-load-relative-directory) (current-directory))
base))
relto))
submod)]
[(pair? relto) (values relto submod)]
[(not dir?)
(values
(and path?
(error 'resolve-module-path-index
"can't resolve \"self\" with non-path relative-to: ~e" relto))
submod)]
[(procedure? relto) (force-relto (relto) dir? #:path? path?)]
[else (values (and path? (current-directory)) submod)])))
(define (path-ss->rkt p)
(let-values ([(base name dir?) (split-path p)])
(if (and (path? name)
(regexp-match #rx"[.]ss$" (path->bytes name)))
(path-replace-suffix p #".rkt")
p)))
(define (combine-submod v p)
(if (null? p)
v
(list* 'submod v p)))
(define (flatten base orig-p)
(let loop ([accum '()] [p orig-p])
(cond
[(null? p) (combine-submod base (reverse accum))]
[(equal? (car p) "..")
(if (null? accum)
(error 'resolve-module-path "too many \"..\"s: ~s"
(combine-submod base orig-p))
(loop (cdr accum) (cdr p)))]
[else (loop (cons (car p) accum) (cdr p))])))
(define (resolve-module-path s relto)
;; relto should be a complete path, #f, or procedure that returns a
;; complete path
(define (get-dir) (force-relto relto #t))
(cond [(symbol? s)
;; use resolver handler:
(resolved-module-path-name
(module-path-index-resolve
(module-path-index-join s #f)))]
[(string? s)
;; Parse Unix-style relative path string
(define-values (dir submod) (get-dir))
(path-ss->rkt
(apply build-path dir (explode-relpath-string s)))]
[(and (or (not (pair? s)) (not (list? s))) (not (path? s)))
#f]
[(or (path? s) (eq? (car s) 'file))
(let ([p (if (path? s) s (expand-user-path (cadr s)))])
(define-values (d submod) (get-dir))
(path-ss->rkt
(path->complete-path
p
(if (path-string? d)
d
(or (current-load-relative-directory)
(current-directory))))))]
[(or (eq? (car s) 'lib)
(eq? (car s) 'quote)
(eq? (car s) 'planet))
;; use resolver handler in this case, too:
(define-values (d submod) (force-relto relto #f #:path? #f))
(resolved-module-path-name
(module-path-index-resolve
(module-path-index-join s #f)))]
[(eq? (car s) 'submod)
(define r (cond
[(or (equal? (cadr s) ".")
(equal? (cadr s) ".."))
(define-values (d submod) (force-relto relto #f))
(combine-submod d submod)]
[else (resolve-module-path (cadr s) relto)]))
(define base-submods (if (and (or (equal? (cadr s) ".")
(equal? (cadr s) ".."))
(pair? r))
(cddr r)
null))
(define base (if (pair? r) (cadr r) r))
(flatten base (append base-submods
(if (equal? (cadr s) "..") (cdr s) (cddr s))))]
[else #f]))
(define (resolve-module-path-index mpi relto)
;; relto must be a complete path
(let-values ([(path base) (module-path-index-split mpi)])
(if path
(resolve-module-path path (resolve-possible-module-path-index base relto))
(let ()
(define sm (module-path-index-submodule mpi))
(define-values (dir submod) (force-relto relto #f))
(combine-submod (path-ss->rkt dir) (if (and sm submod)
(append submod sm)
(or sm submod)))))))
(define (resolve-possible-module-path-index base relto)
(cond [(module-path-index? base)
(resolve-module-path-index base relto)]
[(and (resolved-module-path? base)
(path? (resolved-module-path-name base)))
(resolved-module-path-name base)]
[relto relto]
[else #f]))
(define rel-to-path-string/c
(or/c path-string? (cons/c 'submod (cons/c path-string? (listof symbol?)))))
(define rel-to-path-string/thunk/#f
(or/c rel-to-path-string/c (-> rel-to-path-string/c) false/c))
(provide/contract
[resolve-module-path (module-path?
rel-to-path-string/thunk/#f
. -> . (or/c path? symbol?
(cons/c 'submod (cons/c (or/c path? symbol?)
(listof symbol?)))))]
[resolve-module-path-index ((or/c symbol? module-path-index?)
rel-to-path-string/thunk/#f
. -> . (or/c path? symbol?
(cons/c 'submod (cons/c (or/c path? symbol?)
(listof symbol?)))))])
|