mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 15:58:17 +00:00
vim-patch:77cfc49: runtime(python): highlight ellipsis literals
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
77cfc49060
Co-authored-by: Jon Parise <jon@indelible.org>
This commit is contained in:
@@ -313,6 +313,8 @@ if !exists("python_no_builtin_highlight")
|
||||
syn match pythonAttribute /\.\h\w*/hs=s+1
|
||||
\ contains=ALLBUT,pythonBuiltin,pythonClass,pythonFunction,pythonType,pythonAsync
|
||||
\ transparent
|
||||
" the ellipsis literal `...` can be used in multiple syntactic contexts
|
||||
syn match pythonEllipsis "\.\@1<!.\.\.\ze\.\@!" display
|
||||
endif
|
||||
|
||||
" From the 'Python Library Reference' class hierarchy at the bottom.
|
||||
@@ -368,10 +370,12 @@ if !exists("python_no_doctest_highlight")
|
||||
if !exists("python_no_doctest_code_highlight")
|
||||
syn region pythonDoctest
|
||||
\ start="^\s*>>>\s" end="^\s*$"
|
||||
\ contained contains=ALLBUT,pythonDoctest,pythonClass,pythonFunction,pythonType,@Spell
|
||||
\ contained contains=ALLBUT,pythonDoctest,pythonEllipsis,pythonClass,pythonFunction,pythonType,@Spell
|
||||
syn region pythonDoctestValue
|
||||
\ start=+^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$"
|
||||
\ contained
|
||||
\ contained contains=pythonEllipsis
|
||||
syn match pythonEllipsis "\%(^\s*\)\@<!\.\@1<!\zs\.\.\.\ze\.\@!" display
|
||||
\ contained containedin=pythonDoctest
|
||||
else
|
||||
syn region pythonDoctest
|
||||
\ start="^\s*>>>" end="^\s*$"
|
||||
@@ -414,6 +418,7 @@ if !exists("python_no_number_highlight")
|
||||
endif
|
||||
if !exists("python_no_builtin_highlight")
|
||||
hi def link pythonBuiltin Function
|
||||
hi def link pythonEllipsis pythonBuiltin
|
||||
endif
|
||||
if !exists("python_no_exception_highlight")
|
||||
hi def link pythonExceptions Structure
|
||||
|
Reference in New Issue
Block a user