Skip to content
New issue

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

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

Already on GitHub? # to your account

Support character set, ranges and classes in wildcard modifiers #298

Closed
xiaq opened this issue Dec 18, 2016 · 1 comment
Closed

Support character set, ranges and classes in wildcard modifiers #298

xiaq opened this issue Dec 18, 2016 · 1 comment

Comments

@xiaq
Copy link
Member

xiaq commented Dec 18, 2016

In elvish, wildcards can be modified using the indexing operator []. Right now there is only an all wildcard modifier that makes wildcards match dots in the beginning of filenames. For instance, echo *[all] lists all files in the current directory, including those whose names start with a dot.

Another potential candidate for modifier is the traditional character set and range specification, as in echo [aeiou], which matches files whose names consist of a single vowel, and echo [a-z], which matches file whose names consist of a single lower case letter (let's pretend diacritics do not exist). However, square brackets are already used for list and map literals in elvish. Instead we could implement this as a wildcard modifier: echo ?[aeiou]. This gives character ranges more power: now you can also write echo *[aeiou] to match files whose names consist of any number of vowels.

However, the proposal above conflicts with our current modifier all: if it were to be implemented, *[all] will stand for files whose names consist of letters a and l. (We could make a special case for all, since you shouldn't write two l's, but I detest this kind of special casing.) We need to find a syntax to accommodate both our current "match all" functionality and the character set and range functionality.

There is also "character class" in traditional wildcards that look like [[:digit:]], that we also want to include. We can make all a special character class and therefore share its syntax.

For the choice of syntax, we propose the following possibilities:

  1. Mimic POSIX, sets and ranges being "bare" and classes needing additional square brackets. Character set is [aeiou], range is [a-z], and class is [[:digit:]]. They may be combined: [[:digit:] aeiou a-z] (the space between aeiou and a-z is not mandatory). Elvish is different in that it requires a leading ?, * or **, of course.

  2. Make classes "bare" and make sets and ranges "special classes", one possible syntax being: class is [digit], set is [set:aeiou], and range is [range:a-z]. They may be combined: [digit set:aeiou range:x-z].

@xiaq
Copy link
Member Author

xiaq commented Dec 18, 2016

Let's settle on the second choice, I think it is both cleaner and more extensible. We are already quite un-POSIX anyway.

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

No branches or pull requests

1 participant