diff --git a/pkgs/at-exp-lib/at-exp/lang/reader.rkt b/pkgs/at-exp-lib/at-exp/lang/reader.rkt index 9fae49021c..639ccf6e0d 100644 --- a/pkgs/at-exp-lib/at-exp/lang/reader.rkt +++ b/pkgs/at-exp-lib/at-exp/lang/reader.rkt @@ -16,15 +16,7 @@ (make-meta-reader 'at-exp "language path" - (lambda (bstr) - (let* ([str (bytes->string/latin-1 bstr)] - [sym (string->symbol str)]) - (and (module-path? sym) - (vector - ;; try submod first: - `(submod ,sym reader) - ;; fall back to /lang/reader: - (string->symbol (string-append str "/lang/reader")))))) + lang-reader-module-paths wrap-reader (lambda (orig-read-syntax) (define read-syntax (wrap-reader orig-read-syntax)) diff --git a/pkgs/racket-doc/syntax/scribblings/module-reader.scrbl b/pkgs/racket-doc/syntax/scribblings/module-reader.scrbl index 90d2a22537..cd95217bd7 100644 --- a/pkgs/racket-doc/syntax/scribblings/module-reader.scrbl +++ b/pkgs/racket-doc/syntax/scribblings/module-reader.scrbl @@ -409,7 +409,8 @@ a vector of module paths, they are tried in order using @racket[#f], a reader exception is raised in the same way as when @racket[read-spec] produces a @racket[#f]. The @racketmodname[planet] languages supply a @racket[module-path-parser] that converts a byte -string to a module path. +string to a module path. Lang-extensions like @racketmodname[at-exp] +use @racket[lang-reader-module-paths] as this argument. If loading the module produced by @racket[module-path-parser] succeeds, then the loaded module's @racketidfont{read}, @@ -426,6 +427,14 @@ The procedures generated by @racket[make-meta-reader] are not meant for use with the @racketmodname[syntax/module-reader] language; they are meant to be exported directly.} +@defproc[(lang-reader-module-paths [bstr bytes?]) (or/c #f (vectorof module-path?))]{ +To be used as the third argument to @racket[make-meta-reader] in +lang-extensions like @racketmodname[at-exp]. On success, it returns a +vector of module paths, one of which should point to the reader module +for the @hash-lang[] @racket[bstr] language. These paths are +@racket[(submod base-path reader)] and @racket[base-path/lang/reader]. +} + @defproc[(wrap-read-all [mod-path module-path?] [in input-port?] diff --git a/racket/collects/syntax/module-reader.rkt b/racket/collects/syntax/module-reader.rkt index 4ec90c9891..8d16631d86 100644 --- a/racket/collects/syntax/module-reader.rkt +++ b/racket/collects/syntax/module-reader.rkt @@ -5,6 +5,7 @@ (provide (rename-out [provide-module-reader #%module-begin] [wrap wrap-read-all]) make-meta-reader + lang-reader-module-paths (except-out (all-from-out racket/private/base) #%module-begin)) (define ar? procedure-arity-includes?) @@ -296,4 +297,20 @@ (read-fn inp 'read-syntax (list src) src mod line col pos convert-read-syntax)) - (values -read -read-syntax -get-info))) + (values -read -read-syntax -get-info)) + + ;; lang-reader-module-paths : Byte-String -> (U False (Vectorof Module-Path)) + ;; To be used as the third argument to make-meta-reader in lang-extensions + ;; like at-exp. On success, returns a vector of module paths, one of which + ;; should point to the reader module for the #lang bstr language. + (define (lang-reader-module-paths bstr) + (let* ([str (bytes->string/latin-1 bstr)] + [sym (string->symbol str)]) + (and (module-path? sym) + (vector + ;; try submod first: + `(submod ,sym reader) + ;; fall back to /lang/reader: + (string->symbol (string-append str "/lang/reader")))))) + + )