runtime(python): highlight ellipsis literals#18107
runtime(python): highlight ellipsis literals#18107jparise wants to merge 5 commits intovim:masterfrom
Conversation
|
@zvezdan with this, I believe we now cover all of the builtin constants. |
It can be used in doctest expected result line(s) to indicate anything in between. """Some description.
>>> exec(s) #doctest: +ELLIPSIS
-3.21716034272e-0...7
"""This, unfortunately, shows why the matching needs to be more complex. """A doctest
>>> class MyClass:
... def __init__(self, x):
... try:
... self.a = c
... except ValueError:
... self.b = c
"""now shows all the continuation lines as ellipsis and they should be the same highlight as a regular code and |
Ah, I wasn't aware of
Yes, this is definitely flawed. I'll work on a solution to this case. |
@zvezdan, I believe I've addressed this in the most recent commit. I took this approach:
|
| \ contains=ALLBUT,pythonBuiltin,pythonClass,pythonFunction,pythonType,pythonAsync | ||
| \ transparent | ||
| " the ellipsis literal `...` can be used in multiple syntactic contexts | ||
| syn match pythonEllipsis "\%(^\|[^.]\)\zs\.\.\.\ze\%([^.]\|$\)" display |
There was a problem hiding this comment.
This won't match if it follows another syntax match. E.g. type(...) if the parens are syntax matches. You might want to use a lookahead as well for symmetry but it's not required.
| syn match pythonEllipsis "\%(^\|[^.]\)\zs\.\.\.\ze\%([^.]\|$\)" display | |
| syn match pythonBuiltin "\.\@1<!.\.\.\ze\%([^.]\|$\)" display |
There was a problem hiding this comment.
That's a very nice suggestion. Thanks! I applied it to the latest revision.
(It still needs to be pythonEllipsis due to my most recent change for doctest awareness.)
There was a problem hiding this comment.
Sorry I didn't intend to suggest renaming the group. I think that may have been the name in an earlier draft and it was changed underneath my other open comment window.
a705aed to
d2a9df9
Compare
The ellipsis literal (`...`) can be used in multiple contexts: - Placeholders: `class Foo: ...` - Containers: `Tuple[int, ...]` - Assignments: `x = ...` This is a trickier pattern to match because we can't rely on keyword boundaries, so we instead look for exactly three dots (`...`). This does mean that we will match the `...` portion of `x...x`, which isn't valid Python syntax, but I think that's an acceptable trade-off that avoids making this pattern much more complex. Ref: https://docs.python.org/3/library/constants.html#Ellipsis
Use a negative lookbehind and lookahead to ensure we only match our three consecutive dots. This also eliminates the need to explicitly check for the start and end of the line.
Also expand the set of test cases to include Numpy indexing.
d2a9df9 to
19871e2
Compare
The latest revision now correctly highlights |
|
thanks |
The ellipsis literal (`...`) can be used in multiple contexts: - Placeholders: `class Foo: ...` - Containers: `Tuple[int, ...]` - Assignments: `x = ...` This is a trickier pattern to match because we can't rely on keyword boundaries, so we instead look for exactly three dots (`...`). This does mean that we will match the `...` portion of `x...x`, which isn't valid Python syntax, but I think that's an acceptable trade-off that avoids making this pattern much more complex. Reference: - https://docs.python.org/3/library/constants.html#Ellipsis closes: vim/vim#18107 vim/vim@77cfc49 Co-authored-by: Jon Parise <jon@indelible.org>
The ellipsis literal (`...`) can be used in multiple contexts: - Placeholders: `class Foo: ...` - Containers: `Tuple[int, ...]` - Assignments: `x = ...` This is a trickier pattern to match because we can't rely on keyword boundaries, so we instead look for exactly three dots (`...`). This does mean that we will match the `...` portion of `x...x`, which isn't valid Python syntax, but I think that's an acceptable trade-off that avoids making this pattern much more complex. Reference: - https://docs.python.org/3/library/constants.html#Ellipsis closes: vim/vim#18107 vim/vim@77cfc49 Co-authored-by: Jon Parise <jon@indelible.org>
The ellipsis literal (
...) can be used in multiple contexts:class Foo: ...Tuple[int, ...]x = ...This is a trickier pattern to match because we can't rely on keyword boundaries, so we instead look for exactly three dots (
...).This does mean that we will match the
...portion ofx...x, which isn't valid Python syntax, but I think that's an acceptable trade-off that avoids making this pattern much more complex.Ref: https://docs.python.org/3/library/constants.html#Ellipsis