Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request is opened as a draft, as it is not mergeable yet. It contains a switch to switch between different implementations for number ranges.
After a decision is made on the issue editorconfig/editorconfig#371, the code needs cleanup to only support one implementation. (If it is of interest at all.)
This pull request proposes a new implementation for the translation of editorconfig glob expressions to python regular expressions.
IMO the following points are important:
}xyz{
, see Test globs with braces that are back to back.This was initially implemented in VimScript for my Vim plugin and was than ported to Python.
Numerical Ranges
This implementation translates numerical ranges into regular expressions.
E.g.
{3..10}
becomes(?:\+?(?:[3-9]|10))
{10..3}
also becomes(?:\+?(?:[3-9]|10))
, so the order of numbers is irrelevant{-3..+3}
becomes(?:-(?:[0-3])|\+?(?:[0-3]))
The special thing about the implementation of numeric ranges is that it is
switchable between different implementations. See the top-level variable
NUMBER_MODE
infnmatch.py
.Mode
AS_IS
This implementation should work like the current implementation.
Mode
ZEROS
This implementation allows any number of leading zeros, as proposed by @cxw42 in Py core: numeric ranges don't handle zero correctly.
So:
{3..10}
becomes(?:\+?0*(?:[3-9]|10))
and would match3
+3
Mode
JUSTIFIED
This implementation handles numerical ranges as done by bash. I proposed this in a comment to @cxw42 issue here.
Now
{3..10}
becomes(?:[3-9]|10)
, so leading+
is not matched anymore.{03..10}
becomes(?:0[3-9]|10)
, so all numbers are formatted to equal width. IN this case single-digit numbers need one leading zero.{03..120}
becomes(?:00[3-9]|0[1-9][0-9]|1[0-1][0-9]|120)
. Again the numbers are formatted to equal width, here three digits. So single-digit numbers need two leading zeros, double-digit numbers one.{-3..03}
matches-3
and03
, but not-03
.Status
I didn't change anything outside
fnmatch.py
. So the tests failing with the master branch still fail with this branch. The only on that is fixed isbrackets_slash_inside4
.The implementation passes all current tests related to globbing in mode
AS_IS
andJUSTIFIED
. ForZEROS
one test fails, that test require leading zeros not to be matched.Locally I added some tests for mode 'JUSTIFIED', that I could provide also.
There is one function (
unescapeBrackets
) where I'm unsure if this is really correct.