Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for brace expansion #32

Open
Franciman opened this issue Apr 1, 2019 · 2 comments
Open

Add support for brace expansion #32

Franciman opened this issue Apr 1, 2019 · 2 comments

Comments

@Franciman
Copy link

Franciman commented Apr 1, 2019

Hi, is it possible to add support for globs using this syntax?

/path/to/{a,b}/c

This would match both /path/to/a/c and /path/to/b/c.

In cabal.project you can specify globs using this syntax ( the grammar is specified here).

It would be really useful if one could use Glob to parse the whole syntax supported in cabal.project files, and as far as I understand, this is the only missing piece.

@Deewiant
Copy link
Owner

Deewiant commented Apr 1, 2019

In general in shells brace expansion isn't considered part of path globbing, but it's a more generic expansion syntax. For instance echo x/[ab]/y will only match the paths x/a/y and x/b/y if they exist, whereas echo x/{a,b}/y should always echo x/a/y x/b/y. Thus it's more akin to supporting variable expansion like $foo or arithmetic like $((1 + 2)), which is also why I left it out originally.

Parsing out the brace expansion separately and handing each resulting word over to System.FilePath.Glob.glob would match what real shells do, semantically speaking. I don't think this really belongs in this library, though I can see its value as a convenience.

I don't know what Cabal would do in the x/{a,b}/y case but it probably wants all specified file paths to exist anyway and so doesn't have to bother with this difference. Or then it understands these patterns in a different way to the common shells.

All in all there'd be a bit of research involved to see what other globbing libraries do with brace expansion to scope out reasonable alternatives, and then some possible feature work as a result.

Unfortunately, my usual disclaimer applies: I simply don't have the free time to spare for this kind of larger task any more. PRs are welcome, although in this case I'd first like to see some more analysis and that's probably best handled within this issue.

@Deewiant Deewiant changed the title Add support for union syntax Add support for brace expansion Apr 1, 2019
@Franciman
Copy link
Author

https://cabal.readthedocs.io/en/latest/nix-local-build.html?highlight=packages#cfg-field-packages
Here is some more info about how cabal understands globs.

Anyways, I understand, thank you. I will try to separately unroll braces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants