vimoption2python no longer creates ambiguous regex syntax #939
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.
Python 3.7+ makes it so that a
FutureWarning
notice is printed whenever a regular expression is compiled that contains a sequence which might become ambiguous if nested set operations are added.There are some cases where Deoplete's
vimoption2python
function could produce such a sequence when generating a Python regex for the plugin code to use. In particular, I found this happened from the built-in scheme filetype.The
iskeyword
setting for Scheme is33,35-39,42-43,45-58,60-90,94,95,97-122,126
which is converted byvimoptions2python
into[\w!#-'*-+--:<-Z^_a-z~]
(the issue is the 4th pattern which gets converted into--:
).The change in this PR inserts an additional check before adding a pattern to the list, to determine if it's a character range and either the beginning or end character in the range is
-
. If that is the case, we escape the literal hyphen (e.g. if the pattern was!--
we would escape it to!-\-
instead of!\--
). I don't believe we will encounter the other ambiguous regex syntax cases in this code path.All of that being said, I'm very unfamiliar with Vimscript so I would encourage a thorough review and consideration of any possible edge cases I've missed!