add #:fail' option to collection-file-path' and `collection-path'

Merge a variant to 5.2.1
This commit is contained in:
Matthew Flatt 2012-01-09 15:57:24 -07:00
parent 0d47cea848
commit 23010fc495
10 changed files with 837 additions and 740 deletions

View File

@ -25,7 +25,8 @@
base-if base-cond base-case base-top-interaction
base-open-input-file base-apply base-prop:procedure
base-free-identifier=? base-free-template-identifier=?
base-free-transformer-identifier=? base-free-label-identifier=?)
base-free-transformer-identifier=? base-free-label-identifier=?
base-collection-file-path base-collection-path)
(begin
(require (for-label scheme/base))
(define base-define (racket define))
@ -42,12 +43,15 @@
(define base-free-identifier=? (racket free-identifier=?))
(define base-free-template-identifier=? (racket free-template-identifier=?))
(define base-free-transformer-identifier=? (racket free-transformer-identifier=?))
(define base-free-label-identifier=? (racket free-label-identifier=?))))
(define base-free-label-identifier=? (racket free-label-identifier=?))
(define base-collection-file-path (racket collection-file-path))
(define base-collection-path (racket collection-path))))
@(def-base base-define base-define-syntax base-define-for-syntax base-define-struct
base-if base-cond base-case base-top-interaction
base-open-input-file base-apply base-prop:procedure
base-free-identifier=? base-free-template-identifier=?
base-free-transformer-identifier=? base-free-label-identifier=?)
base-free-transformer-identifier=? base-free-label-identifier=?
base-collection-file-path base-collection-path)
@(define-syntax-rule (additionals racket/base id ...)
(begin
@ -430,7 +434,13 @@ The same as @racket[cleanse-path].}
The same as @racket[list].}
@deftogether[(
@defproc[(collection-file-path [file path-string?] [collection path-string?] ...+) path?]
@defproc[(collection-path [collection path-string?] ...+) path?]
)]{
Like @base-collection-file-path and @base-collection-path, but without
the @racket[#:fail] option.}
@; ----------------------------------------

View File

@ -106,8 +106,31 @@
(define-values (double-flonum?) ; for symmetry with single-flonum?
(lambda (x) (flonum? x)))
(define-values (new:collection-path)
(let ([collection-path (new-lambda (collection
#:fail [fail (lambda (s)
(raise
(exn:fail:filesystem
(string-append "collection-path: " s)
(current-continuation-marks))))]
. collections)
(apply collection-path fail collection collections))])
collection-path))
(define-values (new:collection-file-path)
(let ([collection-file-path (new-lambda (file-name
collection
#:fail [fail (lambda (s)
(raise
(exn:fail:filesystem
(string-append "collection-file-path: " s)
(current-continuation-marks))))]
. collections)
(apply collection-file-path fail file-name collection collections))])
collection-file-path))
(#%provide (all-from-except "more-scheme.rkt" old-case fluid-let)
(all-from "misc.rkt")
(all-from-except "misc.rkt" collection-path collection-file-path)
(all-from "define.rkt")
(all-from-except "letstx-scheme.rkt" -define -define-syntax -define-struct old-cond)
(rename new-lambda lambda)
@ -130,6 +153,8 @@
(rename new:procedure-rename procedure-rename)
(rename new:chaperone-procedure chaperone-procedure)
(rename new:impersonate-procedure impersonate-procedure)
(rename new:collection-path collection-path)
(rename new:collection-file-path collection-file-path)
(all-from-except '#%kernel lambda λ #%app #%module-begin apply prop:procedure
procedure-arity procedure-reduce-arity raise-arity-error
procedure->method procedure-rename

View File

@ -27,13 +27,38 @@
racket/udp
'#%builtin) ; so it's attached
(define new:collection-path
(let ([collection-path (lambda (collection . collections)
(apply collection-path
(lambda (s)
(raise
(exn:fail:filesystem
(string-append "collection-path: " s)
(current-continuation-marks))))
collection collections))])
collection-path))
(define new:collection-file-path
(let ([collection-file-path (lambda (file-name collection . collections)
(apply collection-file-path
(lambda (s)
(raise
(exn:fail:filesystem
(string-append "collection-file-path: " s)
(current-continuation-marks))))
file-name collection collections))])
collection-file-path))
(#%provide require require-for-syntax require-for-template require-for-label
provide provide-for-syntax provide-for-label
(all-from-except racket/private/more-scheme case old-case
log-fatal log-error log-warning log-info log-debug
hash-update hash-update!)
(rename old-case case)
(all-from racket/private/misc)
(all-from-except racket/private/misc collection-path collection-file-path)
(rename new:collection-path collection-path)
(rename new:collection-file-path collection-file-path)
(all-from-except racket/private/stxcase-scheme _ datum datum-case with-datum)
(all-from-except racket/private/letstx-scheme
-define -define-syntax -define-struct

View File

@ -124,21 +124,38 @@ Produces a list of paths as follows:
]}
@defproc[(collection-file-path [file path-string?] [collection path-string?] ...+) path?]{
@defproc*[([(collection-file-path [file path-string?] [collection path-string?] ...+)
path?]
[(collection-file-path [file path-string?] [collection path-string?] ...+
[#:fail fail-proc (string? . -> . any)])
any])]{
Returns the path to the file indicated by @racket[file] in the
collection specified by the @racket[collection]s, where the second
@racket[collection] (if any) names a sub-collection, and so on. If
@racket[file] is not found, but @racket[file] ends in @filepath{.rkt}
and a file with the suffix @filepath{.ss} exists, then the directory
of the @filepath{.ss} file is used. If @racket[file] is not found and
the @filepath{.rkt}/@filepath{.ss} conversion does not apply, but a
directory corresponding to the @racket[collection]s is found, then a
path using the first such directory is returned. Finally, if the
collection is not found, the @exnraise[exn:fail:filesystem].}
@racket[collection] (if any) names a sub-collection, and so on.
If @racket[file] is not found, but @racket[file] ends in
@filepath{.rkt} and a file with the suffix @filepath{.ss} exists, then
the directory of the @filepath{.ss} file is used. If @racket[file] is
not found and the @filepath{.rkt}/@filepath{.ss} conversion does not
apply, but a directory corresponding to the @racket[collection]s is
found, then a path using the first such directory is
returned.
Finally, if the collection is not found, and if @racket[fail-proc] is
provided, then @racket[fail-proc] is applied to an error message (that
does not start @scheme["collection-file-path:"] or otherwise claim a
source), and its result is the result of
@racket[collection-file-path]. If @racket[fail-proc] is not provided
and the collection is not found, then the
@exnraise[exn:fail:filesystem].}
@defproc[(collection-path [collection path-string?] ...+) path?]{
@defproc*[([(collection-path [collection path-string?] ...+)
path?]
[(collection-path [collection path-string?] ...+
[#:fail fail-proc (string? . -> . any)])
any])]{
Like @racket[collection-file-path], but without a specified file name,
so that the first directory indicated by @racket[collection]s is

View File

@ -465,6 +465,20 @@
(test #t module-path? '(planet "foo.rkt" ("robby" "redex.plt") "sub" "deeper"))
(test #t module-path? '(planet "foo%2e.rkt" ("robby%2e" "redex%2e.plt") "sub%2e" "%2edeeper"))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; check collection-path details
(test-values '(not there) (lambda ()
(collection-path "nonesuch"
#:fail (lambda (s)
(test #t string? s)
(values 'not 'there)))))
(test-values '(1 2) (lambda ()
(collection-file-path "none.rkt" "nonesuch"
#:fail (lambda (s)
(test #t string? s)
(values 1 2)))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check 'module-language, `module-compiled-language-info', and `module->language-info'

View File

@ -11,6 +11,8 @@ Added pseudo-random-generator-vector?
Added port-closed-evt
Generalized gcd and lcm to work on rationals
Added module-predefined?
Added optional #:fail argument to collection-file-path and
collection-path
Changed the racket -k command-line flag
racket/class: added send/keyword-apply and dynamic-send
racket/draw: added get-names to color-database<%>

File diff suppressed because it is too large Load Diff

View File

@ -13,12 +13,12 @@
consistently.)
*/
#define MZSCHEME_VERSION "5.2.1.1"
#define MZSCHEME_VERSION "5.2.1.2"
#define MZSCHEME_VERSION_X 5
#define MZSCHEME_VERSION_Y 2
#define MZSCHEME_VERSION_Z 1
#define MZSCHEME_VERSION_W 1
#define MZSCHEME_VERSION_W 2
#define MZSCHEME_VERSION_MAJOR ((MZSCHEME_VERSION_X * 100) + MZSCHEME_VERSION_Y)
#define MZSCHEME_VERSION_MINOR ((MZSCHEME_VERSION_Z * 1000) + MZSCHEME_VERSION_W)

View File

@ -268,24 +268,25 @@
"(lambda(who collection collection-path)"
"(-check-relpath who collection) "
"(for-each(lambda(p)(-check-relpath who p)) collection-path)))"
"(define-values(-check-fail)"
"(lambda(who fail)"
"(unless(and(procedure? fail)"
"(procedure-arity-includes? fail 1))"
" (raise-type-error who \"procedure (arity 1)\" fail))))"
"(define-values(collection-path)"
"(lambda(collection . collection-path) "
"(lambda(fail collection . collection-path) "
"(-check-collection 'collection-path collection collection-path)"
"(find-col-file 'collection-path(lambda(s)"
"(raise"
"(exn:fail:filesystem s(current-continuation-marks))))"
"(-check-fail 'collection-path fail)"
"(find-col-file fail"
" collection collection-path"
" #f)))"
"(define-values(collection-file-path)"
"(lambda(file-name collection . collection-path) "
"(lambda(fail file-name collection . collection-path) "
"(-check-relpath 'collection-file-path file-name)"
"(-check-collection 'collection-file-path collection collection-path)"
"(build-path"
"(find-col-file 'collection-file-path(lambda(s)"
"(raise"
"(exn:fail:filesystem s(current-continuation-marks))))"
"(-check-fail 'collection-file-path fail)"
"(find-col-file fail"
" collection collection-path"
" file-name)"
" file-name)))"
"(define-values(user-links-path)(find-system-path 'links-file))"
"(define-values(user-links-cache)(make-hasheq))"
@ -429,7 +430,7 @@
"(values name collection-path)"
"(normalize-collection-reference base(cons name collection-path))))))))"
"(define-values(find-col-file)"
"(lambda(who fail collection collection-path file-name)"
"(lambda(fail collection collection-path file-name)"
"(let-values(((collection collection-path)"
"(normalize-collection-reference collection collection-path)))"
"(let((all-paths(let((sym(string->symbol(if(path? collection)"
@ -448,6 +449,9 @@
"(hash-ref ht #f null)))"
" null)"
"(current-library-collection-paths)))))"
"(define-values(done)"
"(lambda(p)"
"(if file-name(build-path p file-name) p)))"
"(define-values(*build-path-rep)"
"(lambda(p c)"
"(if(path? p)"
@ -462,7 +466,7 @@
"(let cloop((paths all-paths)(found-col #f))"
"(if(null? paths)"
"(if found-col"
" found-col"
"(done found-col)"
"(let((rest-coll"
"(if(null? collection-path)"
" \"\""
@ -480,8 +484,7 @@
"(cons(car l)(filter f(cdr l)))"
"(filter f(cdr l))))))"
"(fail"
" (format \"~a: collection not found: ~s in any of: ~s~a\" "
" who"
" (format \"collection not found: ~s in any of: ~s~a\" "
"(if(null? collection-path)"
"(to-string collection)"
" (string-append (to-string collection) \"/\" rest-coll))"
@ -509,9 +512,9 @@
" (string-append (substring file-name 0 (- len 4)) \".ss\")))))"
"(and alt-file-name"
"(file-exists?(build-path cpath alt-file-name)))))"
" cpath"
"(done cpath)"
"(cloop(cdr paths)(or found-col cpath)))"
" cpath)"
"(done cpath))"
"(cloop(cdr paths) found-col)))"
"(cloop(cdr paths) found-col)))))))))"
"(define-values(check-suffix-call)"
@ -835,12 +838,13 @@
"(current-load-relative-directory)"
"(current-directory))))"
"(show-collection-err(lambda(s)"
" (let ((s (string-append \"standard-module-name-resolver: \" s)))"
"(if stx"
"(raise-syntax-error"
" #f"
" s"
" stx)"
"(error s))))"
"(error s)))))"
"(ss->rkt(lambda(s)"
"(let((len(string-length s)))"
"(if(and(len . >= . 3)"
@ -859,13 +863,11 @@
"(let-values(((cols file)(split-relative-string(symbol->string s) #f)))"
"(let*((f-file(if(null? cols)"
" \"main.rkt\""
" (string-append file \".rkt\")))"
"(p(find-col-file 'standard-module-name-resolver"
" show-collection-err"
" (string-append file \".rkt\"))))"
"(find-col-file show-collection-err"
"(if(null? cols) file(car cols))"
"(if(null? cols) null(cdr cols))"
" f-file)))"
"(build-path p f-file)))))"
" f-file)))))"
"((string? s)"
"(let*((dir(get-dir)))"
"(or(path-cache-get(cons s dir))"
@ -897,8 +899,8 @@
" \"main.rkt\""
" (if (regexp-match? #rx\"[.]\" file)"
"(ss->rkt file)"
" (string-append file \".rkt\")))))"
"(p(let-values(((cols)"
" (string-append file \".rkt\"))))))"
"(let-values(((cols)"
"(if old-style?"
"(append(if(null?(cddr s))"
" '(\"mzlib\")"
@ -910,12 +912,10 @@
"(if(null? cols)"
"(list file)"
" cols))))"
"(find-col-file 'standard-module-name-resolver"
" show-collection-err"
"(find-col-file show-collection-err"
"(car cols)"
"(cdr cols)"
" f-file))))"
"(build-path p f-file)))))"
" f-file))))))"
"((eq?(car s) 'file)"
"(path-ss->rkt "
"(simplify-path(path->complete-path(expand-user-path(cadr s))(get-dir))))))))"

View File

@ -328,26 +328,28 @@
(-check-relpath who collection)
(for-each (lambda (p) (-check-relpath who p)) collection-path)))
(define-values (-check-fail)
(lambda (who fail)
(unless (and (procedure? fail)
(procedure-arity-includes? fail 1))
(raise-type-error who "procedure (arity 1)" fail))))
(define-values (collection-path)
(lambda (collection . collection-path)
(lambda (fail collection . collection-path)
(-check-collection 'collection-path collection collection-path)
(find-col-file 'collection-path (lambda (s)
(raise
(exn:fail:filesystem s (current-continuation-marks))))
(-check-fail 'collection-path fail)
(find-col-file fail
collection collection-path
#f)))
(define-values (collection-file-path)
(lambda (file-name collection . collection-path)
(lambda (fail file-name collection . collection-path)
(-check-relpath 'collection-file-path file-name)
(-check-collection 'collection-file-path collection collection-path)
(build-path
(find-col-file 'collection-file-path (lambda (s)
(raise
(exn:fail:filesystem s (current-continuation-marks))))
collection collection-path
file-name)
file-name)))
(-check-fail 'collection-file-path fail)
(find-col-file fail
collection collection-path
file-name)))
(define-values (user-links-path) (find-system-path 'links-file))
(define-values (user-links-cache) (make-hasheq))
@ -506,7 +508,7 @@
(normalize-collection-reference base (cons name collection-path))))])))
(define-values (find-col-file)
(lambda (who fail collection collection-path file-name)
(lambda (fail collection collection-path file-name)
(let-values ([(collection collection-path)
(normalize-collection-reference collection collection-path)])
(let ([all-paths (let ([sym (string->symbol (if (path? collection)
@ -528,6 +530,9 @@
null)
;; list of paths:
(current-library-collection-paths)))])
(define-values (done)
(lambda (p)
(if file-name (build-path p file-name) p)))
(define-values (*build-path-rep)
(lambda (p c)
(if (path? p)
@ -544,7 +549,7 @@
(let cloop ([paths all-paths] [found-col #f])
(if (null? paths)
(if found-col
found-col
(done found-col)
(let ([rest-coll
(if (null? collection-path)
""
@ -562,8 +567,7 @@
(cons (car l) (filter f (cdr l)))
(filter f (cdr l))))))
(fail
(format "~a: collection not found: ~s in any of: ~s~a"
who
(format "collection not found: ~s in any of: ~s~a"
(if (null? collection-path)
(to-string collection)
(string-append (to-string collection) "/" rest-coll))
@ -591,12 +595,12 @@
(string-append (substring file-name 0 (- len 4)) ".ss")))])
(and alt-file-name
(file-exists? (build-path cpath alt-file-name)))))
cpath
(done cpath)
;; Look further for specific file, but remember
;; first found directory
(cloop (cdr paths) (or found-col cpath)))
;; Just looking for dir; found it:
cpath)
(done cpath))
;; sub-collection not here; try next instance
;; of the top-level collection
(cloop (cdr paths) found-col)))
@ -961,12 +965,13 @@
(current-load-relative-directory)
(current-directory)))]
[show-collection-err (lambda (s)
(if stx
(raise-syntax-error
#f
s
stx)
(error s)))]
(let ([s (string-append "standard-module-name-resolver: " s)])
(if stx
(raise-syntax-error
#f
s
stx)
(error s))))]
[ss->rkt (lambda (s)
(let ([len (string-length s)])
(if (and (len . >= . 3)
@ -986,13 +991,11 @@
(let-values ([(cols file) (split-relative-string (symbol->string s) #f)])
(let* ([f-file (if (null? cols)
"main.rkt"
(string-append file ".rkt"))]
[p (find-col-file 'standard-module-name-resolver
show-collection-err
(if (null? cols) file (car cols))
(if (null? cols) null (cdr cols))
f-file)])
(build-path p f-file))))]
(string-append file ".rkt"))])
(find-col-file show-collection-err
(if (null? cols) file (car cols))
(if (null? cols) null (cdr cols))
f-file))))]
[(string? s)
(let* ([dir (get-dir)])
(or (path-cache-get (cons s dir))
@ -1025,25 +1028,23 @@
"main.rkt"
(if (regexp-match? #rx"[.]" file)
(ss->rkt file)
(string-append file ".rkt"))))]
[p (let-values ([(cols)
(if old-style?
(append (if (null? (cddr s))
'("mzlib")
(apply append
(map (lambda (p)
(split-relative-string p #t))
(cddr s))))
cols)
(if (null? cols)
(list file)
cols))])
(find-col-file 'standard-module-name-resolver
show-collection-err
(car cols)
(cdr cols)
f-file))])
(build-path p f-file))))]
(string-append file ".rkt"))))])
(let-values ([(cols)
(if old-style?
(append (if (null? (cddr s))
'("mzlib")
(apply append
(map (lambda (p)
(split-relative-string p #t))
(cddr s))))
cols)
(if (null? cols)
(list file)
cols))])
(find-col-file show-collection-err
(car cols)
(cdr cols)
f-file)))))]
[(eq? (car s) 'file)
;; Use filesystem-sensitive `simplify-path' here:
(path-ss->rkt