AlexKnauth / reprovide-lang

a simple racket language for reproviding modules
MIT License
5 stars 0 forks source link

Reprovide all provides from a directory #9

Closed bennn closed 5 years ago

bennn commented 7 years ago

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 files a.rkt and b.rkt, then:

#lang reprovide
"dir/" ;; or something like `(all-from-directory "dir/")`

Should be the same as:

#lang racket/base

(require "dir/a.rkt" "dir/b.rkt")
(provide (all-from-out "dir/a.rkt" "dir/b.rkt"))

Typed Racket does something like this here: https://github.com/racket/typed-racket/blob/master/typed-racket-lib/typed-racket/static-contracts/combinators.rkt

AlexKnauth commented 7 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?)

bennn commented 7 years ago

Yes, directory-in would be good

AlexKnauth commented 7 years ago

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?

AlexKnauth commented 7 years ago

How should I properly reference the directory relative to the path of the file the way require would? I see a few options:

bennn commented 7 years ago

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:

I don't know convert-relative-module-path.

kstrafe commented 5 years ago

Any updates on this? I'd like to see globbing.

AlexKnauth commented 5 years ago

I don't have globbing right now, but I do have directory-in working now in the directory-in branch.

AlexKnauth commented 5 years ago

@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.

bennn commented 5 years ago

There's no glob-quote. That would be a good to have.

I can try to add it this week.

AlexKnauth commented 5 years ago

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.

kstrafe commented 5 years ago

What about directory-in, will that be merged in?

AlexKnauth commented 5 years ago

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.

AlexKnauth commented 5 years ago

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.

bennn commented 5 years ago

proposed glob-quote : https://github.com/racket/racket/pull/2397

jackfirth commented 5 years ago

Hey folks, just stumbled across glob-in and wanted to say it's really awesome 🎉 Thank you all!