Closed bennn closed 5 years ago
I want to keep it as close to the syntax of require
as possible. Would it be okay if instead we made all-from-directory
as a normal require-transformer, and allowed using it in #lang reprovide
modules?
(Edit: Or to follow the convention of require-transformers, directory-in
?)
Yes, directory-in
would be good
What types of files should directory-in
try to require? In the example you gave the code only requires files with a .rkt
extension, which is fine for a private TR thing, but I'm not sure that's what this should do. Should it instead include all the files which can be read as valid modules, either #lang
files or (module ...)
s-expressions?
How should I properly reference the directory relative to the path of the file the way require would? I see a few options:
(current-directory)
: really bad, breaks whenever it's compiled from a different directorysyntax-source
: really bad, breaks when a macro generates itdefine-runtime-path
? I don't know how I would get it to refer to the correct thing...convert-relative-module-path
or current-require-module-path
: This seems like it should be the Right Way, but convert-relative-module-path
is just returning the same path I'm giving it, which ends up behaving just like if I used (current-directory), and current-require-module-path
is false within my require transformer.For types of files, I think .rkt
. Maybe .rkt
can be the default and directory-in
can take an optional suffix.
Or maybe (glob-in glob-str)
for more freedom (even (glob-in "parent-dir/**/*.rkt")
)
(define-runtime-path directory-in-cwd ".")
seems best offhand .. maybe syntax-local-lift-module-end-declaration
will put it in the right place. I guess another problem is that each use of (directory-in ...)
will need to either:
define-runtime-path
, based on some statedefine-runtime-path
and use a new identifierI don't know convert-relative-module-path
.
Any updates on this? I'd like to see globbing.
I don't have globbing right now, but I do have directory-in
working now in the directory-in branch.
@bennn Is there a "quoting" operation for globs? A glob-quote
, that would be analogous to regexp-quote
? I want to make sure that if glob-special characters appear in the parent directory they will be encoded in the correct way; that I can make a glob match exactly those characters and not interpret them as glob-special characters.
There's no glob-quote
. That would be a good to have.
I can try to add it this week.
Just added glob-in
as a require form that can be used within #lang reprovide
. I'll still leave this open until I get to making documentation for it eventually.
What about directory-in
, will that be merged in?
Probably not. I technically “works” as in it does generate a require for every file in the given directory. However, this is unlikely to make sense as-is. It literally generates a require for every file that has #lang
at the top, even if it that file was intended to be a text file, an auto save file, a preproccessor template, or anything else. When users use glob-in
that won’t be as much of a problem because they will probably specify the file-extensions they want explicitly.
I've added some initial documentation with a few examples and a pointer to the docs for Globbing, so I think now I can close this.
proposed glob-quote
: https://github.com/racket/racket/pull/2397
Hey folks, just stumbled across glob-in
and wanted to say it's really awesome 🎉 Thank you all!
feature request: reproviding a
path-string?
that refers to a directory reprovides from all files in the directory.So if I had a directory
dir/
with filesa.rkt
andb.rkt
, then:Should be the same as:
Typed Racket does something like this here: https://github.com/racket/typed-racket/blob/master/typed-racket-lib/typed-racket/static-contracts/combinators.rkt