From e5c90c6b101c9d6602305df1088a3d2cad15f0e7 Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 9 Jan 2019 15:15:36 +0000 Subject: [PATCH 01/19] Remove highlight link from `pythonDot` to `Normal` Linking `pythonDot` to `Normal` breaks `CursorLine` highlighting. ``` hi Normal guifg=#ffffff guibg=#000000 hi CursorLine guibg=#111111 ``` Closes #48 --- syntax/python.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 913da9d..7761ec9 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -414,7 +414,6 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonDecorator Define HiLink pythonDottedName Function - HiLink pythonDot Normal HiLink pythonComment Comment if !s:Enabled('g:python_highlight_file_headers_as_comments') From 7ecb80f0fccfdf90038490b297c11bff6f7556c0 Mon Sep 17 00:00:00 2001 From: Caleb Donovick Date: Tue, 18 Dec 2018 15:37:19 -0800 Subject: [PATCH 02/19] Add `pythonNone` to `pythonExpression` Closes #54 --- syntax/python.vim | 2 +- tests/test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 7761ec9..3f4c967 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -92,7 +92,7 @@ else syn match pythonStatement '\' nextgroup=pythonFunction skipwhite syn match pythonStatement '\' syn match pythonStatement '\' - syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonBuiltinObj,pythonBuiltinFunc + syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonBuiltinObj,pythonBuiltinFunc endif diff --git a/tests/test.py b/tests/test.py index 08d5a69..6f00b26 100644 --- a/tests/test.py +++ b/tests/test.py @@ -233,7 +233,7 @@ async def Test b"${test} ${test ${test}aname $$$ $test+nope" f"{var}...{arr[123]} normal {var['{'] // 0xff} \"xzcb\" 'xzcb' {var['}'] + 1} text" -f"{expr1 if True or False else expr2} wow {','.join(c.lower() for c in 'asdf')}" +f"{expr1 if True or False else expr2} {None} wow {','.join(c.lower() for c in 'asdf')}" f"hello {expr:.2f} yes {(lambda: 0b1)():#03x} lol {var!r}" f'brackets: {{ 1 + 2 }} and {{{{ 3 + 4 }}}}' fr'this {that}' From 0a925278f7444ce28bfccfabeabee65d706da531 Mon Sep 17 00:00:00 2001 From: Caleb Donovick Date: Tue, 18 Dec 2018 15:29:50 -0800 Subject: [PATCH 03/19] Split builtin objects / types Closes #55 --- README.md | 1 + doc/python-syntax.txt | 3 +++ syntax/python.vim | 21 ++++++++++++++++----- tests/test.py | 2 ++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8c35ec2..c1b6b0d 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ let g:python_highlight_all = 1 | `b:python_version_2` | Python 2 mode (buffer local) | `0` | | `g:python_highlight_builtins` | Highlight builtin functions and objects | `0` | | `g:python_highlight_builtin_objs` | Highlight builtin objects only | `0` | +| `g:python_highlight_builtin_types` | Highlight builtin types only | `0` | | `g:python_highlight_builtin_funcs` | Highlight builtin functions only | `0` | | `g:python_highlight_builtin_funcs_kwarg` | Highlight builtin functions when used as kwarg | `1` | | `g:python_highlight_exceptions` | Highlight standard exceptions | `0` | diff --git a/doc/python-syntax.txt b/doc/python-syntax.txt index a1ccf16..01bd1fe 100644 --- a/doc/python-syntax.txt +++ b/doc/python-syntax.txt @@ -62,6 +62,9 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: > `g:python_highlight_builtin_objs` (default `0`) Highlight builtin objects only +`g:python_highlight_builtin_types` (default `0`) + Highlight builtin types only + `g:python_highlight_builtin_funcs` (default `0`) Highlight builtin functions only diff --git a/syntax/python.vim b/syntax/python.vim index 3f4c967..2f9a47e 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -44,6 +44,7 @@ if s:Enabled('g:python_highlight_all') if s:Enabled('g:python_highlight_builtins') call s:EnableByDefault('g:python_highlight_builtin_objs') call s:EnableByDefault('g:python_highlight_builtin_funcs') + call s:EnableByDefault('g:python_highlight_builtin_types') endif call s:EnableByDefault('g:python_highlight_exceptions') call s:EnableByDefault('g:python_highlight_string_formatting') @@ -92,7 +93,7 @@ else syn match pythonStatement '\' nextgroup=pythonFunction skipwhite syn match pythonStatement '\' syn match pythonStatement '\' - syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonBuiltinObj,pythonBuiltinFunc + syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType endif @@ -330,14 +331,13 @@ else endif " -" Builtin objects and types +" Builtin objects " if s:Enabled('g:python_highlight_builtin_objs') syn keyword pythonNone None syn keyword pythonBoolean True False - syn keyword pythonBuiltinObj Ellipsis NotImplemented - syn match pythonBuiltinObj '\v\.@' + syn keyword pythonSingleton Ellipsis NotImplemented syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__ endif @@ -368,6 +368,15 @@ if s:Enabled('g:python_highlight_builtin_funcs') unlet s:funcs_re endif +" +" Builtin types +" + +if s:Enabled('g:python_highlight_builtin_types') + syn match pythonBuiltinType '\v\.@' +endif + + " " Builtin exceptions and warnings " @@ -469,9 +478,11 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonBoolean Boolean HiLink pythonNone Constant + HiLink pythonSingleton Constant - HiLink pythonBuiltinObj Structure + HiLink pythonBuiltinObj Identifier HiLink pythonBuiltinFunc Function + HiLink pythonBuiltinType Structure HiLink pythonExClass Structure HiLink pythonClassVar Identifier diff --git a/tests/test.py b/tests/test.py index 6f00b26..0f75ead 100644 --- a/tests/test.py +++ b/tests/test.py @@ -38,6 +38,8 @@ async def Test True False Ellipsis None NotImplemented +__debug__ __doc__ __file__ __name__ __package__ __loader__ __spec__ __path__ __cached__ + # Bultin types bool bytearray dict float frozenset int list object set str tuple From 8d3c0af77592254f342ca7f35ba3721218e83b34 Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 9 Jan 2019 15:59:09 +0000 Subject: [PATCH 04/19] Add builtin function `breakpoint` Fixes #46 --- syntax/python.vim | 2 +- tests/test.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 2f9a47e..9169389 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -355,7 +355,7 @@ if s:Enabled('g:python_highlight_builtin_funcs') let s:funcs_re .= '|print' endif else - let s:funcs_re .= '|ascii|exec|print' + let s:funcs_re .= '|ascii|breakpoint|exec|print' endif let s:funcs_re = 'syn match pythonBuiltinFunc ''\v\.@' diff --git a/tests/test.py b/tests/test.py index 0f75ead..a843fc7 100644 --- a/tests/test.py +++ b/tests/test.py @@ -52,6 +52,7 @@ async def Test any() bin() bool() +breakpoint() bytearray() callable() chr() From 41ad5136c47b95e8b00f6eef2283990eea8a136a Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 9 Jan 2019 16:13:17 +0000 Subject: [PATCH 05/19] Fix `PendingDeprecationWarning` typo Fixes #44 --- syntax/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 9169389..6d895d2 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -382,7 +382,7 @@ endif " if s:Enabled('g:python_highlight_exceptions') - let s:exs_re = 'BaseException|Exception|ArithmeticError|LookupError|EnvironmentError|AssertionError|AttributeError|BufferError|EOFError|FloatingPointError|GeneratorExit|IOError|ImportError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|ReferenceError|RuntimeError|StopIteration|SyntaxError|IndentationError|TabError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|VMSError|WindowsError|ZeroDivisionError|Warning|UserWarning|BytesWarning|DeprecationWarning|PendingDepricationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning' + let s:exs_re = 'BaseException|Exception|ArithmeticError|LookupError|EnvironmentError|AssertionError|AttributeError|BufferError|EOFError|FloatingPointError|GeneratorExit|IOError|ImportError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|ReferenceError|RuntimeError|StopIteration|SyntaxError|IndentationError|TabError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|VMSError|WindowsError|ZeroDivisionError|Warning|UserWarning|BytesWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning' if s:Python2Syntax() let s:exs_re .= '|StandardError' From 1df5e5aaf8c7050795e2994329a23b3fd24eb161 Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 9 Jan 2019 16:17:04 +0000 Subject: [PATCH 06/19] Fix parsing floats with no number trailing the `.` Fixes #41 --- syntax/python.vim | 2 +- tests/test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 6d895d2..8fc77e3 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -327,7 +327,7 @@ else syn match pythonFloat '\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=\>' display syn match pythonFloat '\<\d\%([_0-9]*\d\)\=[eE][+-]\=\d\%([_0-9]*\d\)\=[jJ]\=\>' display - syn match pythonFloat '\<\d\%([_0-9]*\d\)\=\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=' display + syn match pythonFloat '\<\d\%([_0-9]*\d\)\=\.\d\=\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=' display endif " diff --git a/tests/test.py b/tests/test.py index a843fc7..5c494fd 100644 --- a/tests/test.py +++ b/tests/test.py @@ -186,7 +186,7 @@ async def Test # Numbers -0 1 2 9 10 0x1f .3 12.34 0j 124j 34.2E-3 0b10 0o77 1023434 0x0 +0 1 2 9 10 0x1f 1. .3 12.34 0j 124j 34.2E-3 0b10 0o77 1023434 0x0 1_1 1_1.2_2 1_2j 0x_1f 0x1_f 34_56e-3 34_56e+3_1 0o7_7 # Erroneous numbers From 53ea235863b6aec3d9616e4a8ef7baa60a061463 Mon Sep 17 00:00:00 2001 From: antoinemadec Date: Wed, 19 Feb 2020 16:17:14 -0800 Subject: [PATCH 07/19] Implement function call highlighting Closes #63 --- README.md | 1 + doc/python-syntax.txt | 3 +++ syntax/python.vim | 24 +++++++++++++++++++----- tests/test.py | 6 ++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c1b6b0d..37062f7 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ let g:python_highlight_all = 1 | `g:python_highlight_indent_errors` | Highlight indentation errors | `0` | | `g:python_highlight_space_errors` | Highlight trailing spaces | `0` | | `g:python_highlight_doctests` | Highlight doc-tests | `0` | +| `g:python_highlight_func_calls` | Highlight functions calls | `0` | | `g:python_highlight_class_vars` | Highlight class variables `self` and `cls` | `0` | | `g:python_highlight_operators` | Highlight all operators | `0` | | `g:python_highlight_all` | Enable all highlight options above, except for previously set. | `0` | diff --git a/doc/python-syntax.txt b/doc/python-syntax.txt index 01bd1fe..8c8f8f2 100644 --- a/doc/python-syntax.txt +++ b/doc/python-syntax.txt @@ -92,6 +92,9 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: > `g:python_highlight_doctests` (default `0`) Highlight doc-tests +`g:python_highlight_func_calls` (default `0`) + Highlight functions calls + `g:python_highlight_class_vars` (default `0`) Highlight class variables `self` and `cls` diff --git a/syntax/python.vim b/syntax/python.vim index 8fc77e3..0a29486 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -54,6 +54,7 @@ if s:Enabled('g:python_highlight_all') call s:EnableByDefault('g:python_highlight_space_errors') call s:EnableByDefault('g:python_highlight_doctests') call s:EnableByDefault('g:python_print_as_function') + call s:EnableByDefault('g:python_highlight_func_calls') call s:EnableByDefault('g:python_highlight_class_vars') call s:EnableByDefault('g:python_highlight_operators') endif @@ -64,7 +65,7 @@ endif syn keyword pythonStatement break continue del return pass yield global assert lambda with syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite -syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite +syn keyword pythonStatement def class nextgroup=pythonFunctionContained skipwhite if s:Enabled('g:python_highlight_class_vars') syn keyword pythonClassVar self cls endif @@ -85,12 +86,12 @@ if s:Python2Syntax() endif syn keyword pythonStatement exec syn keyword pythonImport as - syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained + syn match pythonFunctionContained '[a-zA-Z_][a-zA-Z0-9_]*' display contained else syn keyword pythonStatement as nonlocal syn match pythonStatement '\v\.@' - syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained - syn match pythonStatement '\' nextgroup=pythonFunction skipwhite + syn match pythonFunctionContained '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained + syn match pythonStatement '\' nextgroup=pythonFunctionContained skipwhite syn match pythonStatement '\' syn match pythonStatement '\' syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType @@ -394,6 +395,18 @@ if s:Enabled('g:python_highlight_exceptions') unlet s:exs_re endif +" +" Function calls +" + +if s:Enabled('g:python_highlight_func_calls') + syn match pythonFunctionCall '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\ze\%(\s*(\)' +endif + +" +" Misc +" + if s:Enabled('g:python_slow_sync') syn sync minlines=2000 else @@ -415,7 +428,8 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonStatement Statement HiLink pythonRaiseFromStatement Statement HiLink pythonImport Include - HiLink pythonFunction Function + HiLink pythonFunctionContained Function + HiLink pythonFunctionCall Function HiLink pythonConditional Conditional HiLink pythonRepeat Repeat HiLink pythonException Exception diff --git a/tests/test.py b/tests/test.py index 5c494fd..e6e8d1b 100644 --- a/tests/test.py +++ b/tests/test.py @@ -18,8 +18,14 @@ yield from def functionname +functionname() +functionname () +functionname () +test.functionname() +test.functionname () class Classname def функция +функция() class Класс # Keywords: Python 2 From 6890a367fb4217523225cae2d90a2f1cbf4f09ec Mon Sep 17 00:00:00 2001 From: nfnty Date: Tue, 25 Feb 2020 11:07:09 +0000 Subject: [PATCH 08/19] Fix indentation --- syntax/python.vim | 580 +++++++++++++++++++++++----------------------- 1 file changed, 290 insertions(+), 290 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 0a29486..6a602e9 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -1,9 +1,9 @@ " For version 5.x: Clear all syntax items " For versions greater than 6.x: Quit when a syntax file was already loaded if v:version < 600 - syntax clear + syntax clear elseif exists('b:current_syntax') - finish + finish endif " @@ -14,22 +14,22 @@ command! -buffer Python3Syntax let b:python_version_2 = 0 | let &syntax=&syntax " Enable option if it's not defined function! s:EnableByDefault(name) - if !exists(a:name) - let {a:name} = 1 - endif + if !exists(a:name) + let {a:name} = 1 + endif endfunction " Check if option is enabled function! s:Enabled(name) - return exists(a:name) && {a:name} + return exists(a:name) && {a:name} endfunction " Is it Python 2 syntax? function! s:Python2Syntax() - if exists('b:python_version_2') - return b:python_version_2 - endif - return s:Enabled('g:python_version_2') + if exists('b:python_version_2') + return b:python_version_2 + endif + return s:Enabled('g:python_version_2') endfunction " @@ -40,23 +40,23 @@ call s:EnableByDefault('g:python_slow_sync') call s:EnableByDefault('g:python_highlight_builtin_funcs_kwarg') if s:Enabled('g:python_highlight_all') - call s:EnableByDefault('g:python_highlight_builtins') - if s:Enabled('g:python_highlight_builtins') - call s:EnableByDefault('g:python_highlight_builtin_objs') - call s:EnableByDefault('g:python_highlight_builtin_funcs') - call s:EnableByDefault('g:python_highlight_builtin_types') - endif - call s:EnableByDefault('g:python_highlight_exceptions') - call s:EnableByDefault('g:python_highlight_string_formatting') - call s:EnableByDefault('g:python_highlight_string_format') - call s:EnableByDefault('g:python_highlight_string_templates') - call s:EnableByDefault('g:python_highlight_indent_errors') - call s:EnableByDefault('g:python_highlight_space_errors') - call s:EnableByDefault('g:python_highlight_doctests') - call s:EnableByDefault('g:python_print_as_function') - call s:EnableByDefault('g:python_highlight_func_calls') - call s:EnableByDefault('g:python_highlight_class_vars') - call s:EnableByDefault('g:python_highlight_operators') + call s:EnableByDefault('g:python_highlight_builtins') + if s:Enabled('g:python_highlight_builtins') + call s:EnableByDefault('g:python_highlight_builtin_objs') + call s:EnableByDefault('g:python_highlight_builtin_funcs') + call s:EnableByDefault('g:python_highlight_builtin_types') + endif + call s:EnableByDefault('g:python_highlight_exceptions') + call s:EnableByDefault('g:python_highlight_string_formatting') + call s:EnableByDefault('g:python_highlight_string_format') + call s:EnableByDefault('g:python_highlight_string_templates') + call s:EnableByDefault('g:python_highlight_indent_errors') + call s:EnableByDefault('g:python_highlight_space_errors') + call s:EnableByDefault('g:python_highlight_doctests') + call s:EnableByDefault('g:python_print_as_function') + call s:EnableByDefault('g:python_highlight_func_calls') + call s:EnableByDefault('g:python_highlight_class_vars') + call s:EnableByDefault('g:python_highlight_operators') endif " @@ -67,7 +67,7 @@ syn keyword pythonStatement break continue del return pass yield global asse syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite syn keyword pythonStatement def class nextgroup=pythonFunctionContained skipwhite if s:Enabled('g:python_highlight_class_vars') - syn keyword pythonClassVar self cls + syn keyword pythonClassVar self cls endif syn keyword pythonRepeat for while syn keyword pythonConditional if elif else @@ -81,20 +81,20 @@ syn match pythonImport '^\s*\zsfrom\>' if s:Python2Syntax() - if !s:Enabled('g:python_print_as_function') - syn keyword pythonStatement print - endif - syn keyword pythonStatement exec - syn keyword pythonImport as - syn match pythonFunctionContained '[a-zA-Z_][a-zA-Z0-9_]*' display contained + if !s:Enabled('g:python_print_as_function') + syn keyword pythonStatement print + endif + syn keyword pythonStatement exec + syn keyword pythonImport as + syn match pythonFunctionContained '[a-zA-Z_][a-zA-Z0-9_]*' display contained else - syn keyword pythonStatement as nonlocal - syn match pythonStatement '\v\.@' - syn match pythonFunctionContained '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained - syn match pythonStatement '\' nextgroup=pythonFunctionContained skipwhite - syn match pythonStatement '\' - syn match pythonStatement '\' - syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType + syn keyword pythonStatement as nonlocal + syn match pythonStatement '\v\.@' + syn match pythonFunctionContained '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained + syn match pythonStatement '\' nextgroup=pythonFunctionContained skipwhite + syn match pythonStatement '\' + syn match pythonStatement '\' + syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType endif @@ -113,9 +113,9 @@ syn match pythonError '[$?]\|\([-+@%&|^~]\)\1\{1,}\|\([=*/<>]\)\2\{2,} syn match pythonDecorator '^\s*\zs@' display nextgroup=pythonDottedName skipwhite if s:Python2Syntax() - syn match pythonDottedName '[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*' display contained + syn match pythonDottedName '[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*' display contained else - syn match pythonDottedName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*' display contained + syn match pythonDottedName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*' display contained endif syn match pythonDot '\.' display containedin=pythonDottedName @@ -125,8 +125,8 @@ syn match pythonDot '\.' display containedin=pythonDottedName syn match pythonComment '#.*$' display contains=pythonTodo,@Spell if !s:Enabled('g:python_highlight_file_headers_as_comments') - syn match pythonRun '\%^#!.*$' - syn match pythonCoding '\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$' + syn match pythonRun '\%^#!.*$' + syn match pythonCoding '\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$' endif syn keyword pythonTodo TODO FIXME XXX contained @@ -139,12 +139,12 @@ syn match pythonError '\<\d\+[^0-9[:space:]]\+\>' display " Mixing spaces and tabs also may be used for pretty formatting multiline " statements if s:Enabled('g:python_highlight_indent_errors') - syn match pythonIndentError '^\s*\%( \t\|\t \)\s*\S'me=e-1 display + syn match pythonIndentError '^\s*\%( \t\|\t \)\s*\S'me=e-1 display endif " Trailing space errors if s:Enabled('g:python_highlight_space_errors') - syn match pythonSpaceError '\s\+$' display + syn match pythonSpaceError '\s\+$' display endif " @@ -152,20 +152,20 @@ endif " if s:Python2Syntax() - " Python 2 strings - syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell - syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell - syn region pythonString start=+[bB]\="""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell - syn region pythonString start=+[bB]\='''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell + " Python 2 strings + syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell + syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell + syn region pythonString start=+[bB]\="""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell + syn region pythonString start=+[bB]\='''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell else - " Python 3 byte strings - syn region pythonBytes start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell - syn region pythonBytes start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell - syn region pythonBytes start=+[bB]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell - syn region pythonBytes start=+[bB]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell - - syn match pythonBytesError '.\+' display contained - syn match pythonBytesContent '[\u0000-\u00ff]\+' display contained contains=pythonBytesEscape,pythonBytesEscapeError + " Python 3 byte strings + syn region pythonBytes start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell + syn region pythonBytes start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell + syn region pythonBytes start=+[bB]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell + syn region pythonBytes start=+[bB]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell + + syn match pythonBytesError '.\+' display contained + syn match pythonBytesContent '[\u0000-\u00ff]\+' display contained contains=pythonBytesEscape,pythonBytesEscapeError endif syn match pythonBytesEscape +\\[abfnrtv'"\\]+ display contained @@ -183,100 +183,100 @@ syn match pythonUniEscape '\\N{[A-Z ]\+}' display contained syn match pythonUniEscapeError '\\N{[^A-Z ]\+}' display contained if s:Python2Syntax() - " Python 2 Unicode strings - syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell - syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell - syn region pythonUniString start=+[uU]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell - syn region pythonUniString start=+[uU]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell + " Python 2 Unicode strings + syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell + syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell + syn region pythonUniString start=+[uU]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell + syn region pythonUniString start=+[uU]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell else - " Python 3 strings - syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell - syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell - syn region pythonString start=+'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell - syn region pythonString start=+"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell - - syn region pythonFString start=+[fF]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell - syn region pythonFString start=+[fF]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell - syn region pythonFString start=+[fF]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell - syn region pythonFString start=+[fF]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell + " Python 3 strings + syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell + syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell + syn region pythonString start=+'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell + syn region pythonString start=+"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell + + syn region pythonFString start=+[fF]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell + syn region pythonFString start=+[fF]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell + syn region pythonFString start=+[fF]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell + syn region pythonFString start=+[fF]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell endif if s:Python2Syntax() - " Python 2 Unicode raw strings - syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell - syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell - syn region pythonUniRawString start=+[uU][rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell - syn region pythonUniRawString start=+[uU][rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell - - syn match pythonUniRawEscape '\%([^\\]\%(\\\\\)*\)\@<=\\u\x\{4}' display contained - syn match pythonUniRawEscapeError '\%([^\\]\%(\\\\\)*\)\@<=\\u\x\{,3}\X' display contained + " Python 2 Unicode raw strings + syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell + syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell + syn region pythonUniRawString start=+[uU][rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell + syn region pythonUniRawString start=+[uU][rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell + + syn match pythonUniRawEscape '\%([^\\]\%(\\\\\)*\)\@<=\\u\x\{4}' display contained + syn match pythonUniRawEscapeError '\%([^\\]\%(\\\\\)*\)\@<=\\u\x\{,3}\X' display contained endif " Python 2/3 raw strings if s:Python2Syntax() - syn region pythonRawString start=+[bB]\=[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell - syn region pythonRawString start=+[bB]\=[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell - syn region pythonRawString start=+[bB]\=[rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell - syn region pythonRawString start=+[bB]\=[rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell + syn region pythonRawString start=+[bB]\=[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell + syn region pythonRawString start=+[bB]\=[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell + syn region pythonRawString start=+[bB]\=[rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell + syn region pythonRawString start=+[bB]\=[rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell else - syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell - syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell - syn region pythonRawString start=+[rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell - syn region pythonRawString start=+[rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell - - syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell - syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell - syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell - syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest,pythonSpaceError,@Spell - - syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell - syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell - syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell - syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell + syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell + syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell + syn region pythonRawString start=+[rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell + syn region pythonRawString start=+[rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell + + syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell + syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell + syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell + syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest,pythonSpaceError,@Spell + + syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell + syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell + syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell + syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell endif syn match pythonRawEscape +\\['"]+ display contained if s:Enabled('g:python_highlight_string_formatting') - " % operator string formatting - if s:Python2Syntax() - syn match pythonStrFormatting '%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString,pythonBytesContent - syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString,pythonBytesContent - else - syn match pythonStrFormatting '%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonRawString,pythonBytesContent - syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonRawString,pythonBytesContent - endif + " % operator string formatting + if s:Python2Syntax() + syn match pythonStrFormatting '%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString,pythonBytesContent + syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString,pythonBytesContent + else + syn match pythonStrFormatting '%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonRawString,pythonBytesContent + syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonRawString,pythonBytesContent + endif endif if s:Enabled('g:python_highlight_string_format') - " str.format syntax - if s:Python2Syntax() - syn match pythonStrFormat '{{\|}}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString - syn match pythonStrFormat '{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString - else - syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString - syn region pythonStrInterpRegion start="{"he=e+1,rs=e+1 end="\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}"hs=s-1,re=s-1 extend contained containedin=pythonFString,pythonRawFString contains=pythonStrInterpRegion,@pythonExpression - syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString,pythonFString,pythonRawFString - endif + " str.format syntax + if s:Python2Syntax() + syn match pythonStrFormat '{{\|}}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString + syn match pythonStrFormat '{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString + else + syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString + syn region pythonStrInterpRegion start="{"he=e+1,rs=e+1 end="\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}"hs=s-1,re=s-1 extend contained containedin=pythonFString,pythonRawFString contains=pythonStrInterpRegion,@pythonExpression + syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString,pythonFString,pythonRawFString + endif endif if s:Enabled('g:python_highlight_string_templates') - " string.Template format - if s:Python2Syntax() - syn match pythonStrTemplate '\$\$' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString - syn match pythonStrTemplate '\${[a-zA-Z_][a-zA-Z0-9_]*}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString - syn match pythonStrTemplate '\$[a-zA-Z_][a-zA-Z0-9_]*' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString - else - syn match pythonStrTemplate '\$\$' contained containedin=pythonString,pythonRawString - syn match pythonStrTemplate '\${[a-zA-Z_][a-zA-Z0-9_]*}' contained containedin=pythonString,pythonRawString - syn match pythonStrTemplate '\$[a-zA-Z_][a-zA-Z0-9_]*' contained containedin=pythonString,pythonRawString - endif + " string.Template format + if s:Python2Syntax() + syn match pythonStrTemplate '\$\$' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString + syn match pythonStrTemplate '\${[a-zA-Z_][a-zA-Z0-9_]*}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString + syn match pythonStrTemplate '\$[a-zA-Z_][a-zA-Z0-9_]*' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString + else + syn match pythonStrTemplate '\$\$' contained containedin=pythonString,pythonRawString + syn match pythonStrTemplate '\${[a-zA-Z_][a-zA-Z0-9_]*}' contained containedin=pythonString,pythonRawString + syn match pythonStrTemplate '\$[a-zA-Z_][a-zA-Z0-9_]*' contained containedin=pythonString,pythonRawString + endif endif if s:Enabled('g:python_highlight_doctests') - " DocTests - syn region pythonDocTest start='^\s*>>>' skip=+\\'+ end=+'''+he=s-1 end='^\s*$' contained - syn region pythonDocTest2 start='^\s*>>>' skip=+\\"+ end=+"""+he=s-1 end='^\s*$' contained + " DocTests + syn region pythonDocTest start='^\s*>>>' skip=+\\'+ end=+'''+he=s-1 end='^\s*$' contained + syn region pythonDocTest2 start='^\s*>>>' skip=+\\"+ end=+"""+he=s-1 end='^\s*$' contained endif " @@ -284,51 +284,51 @@ endif " if s:Python2Syntax() - syn match pythonHexError '\<0[xX]\x*[g-zG-Z]\+\x*[lL]\=\>' display - syn match pythonOctError '\<0[oO]\=\o*\D\+\d*[lL]\=\>' display - syn match pythonBinError '\<0[bB][01]*\D\+\d*[lL]\=\>' display + syn match pythonHexError '\<0[xX]\x*[g-zG-Z]\+\x*[lL]\=\>' display + syn match pythonOctError '\<0[oO]\=\o*\D\+\d*[lL]\=\>' display + syn match pythonBinError '\<0[bB][01]*\D\+\d*[lL]\=\>' display - syn match pythonHexNumber '\<0[xX]\x\+[lL]\=\>' display - syn match pythonOctNumber '\<0[oO]\o\+[lL]\=\>' display - syn match pythonBinNumber '\<0[bB][01]\+[lL]\=\>' display + syn match pythonHexNumber '\<0[xX]\x\+[lL]\=\>' display + syn match pythonOctNumber '\<0[oO]\o\+[lL]\=\>' display + syn match pythonBinNumber '\<0[bB][01]\+[lL]\=\>' display - syn match pythonNumberError '\<\d\+\D[lL]\=\>' display - syn match pythonNumber '\<\d[lL]\=\>' display - syn match pythonNumber '\<[0-9]\d\+[lL]\=\>' display - syn match pythonNumber '\<\d\+[lLjJ]\>' display + syn match pythonNumberError '\<\d\+\D[lL]\=\>' display + syn match pythonNumber '\<\d[lL]\=\>' display + syn match pythonNumber '\<[0-9]\d\+[lL]\=\>' display + syn match pythonNumber '\<\d\+[lLjJ]\>' display - syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*[lL]\=\>' display - syn match pythonBinError '\<0[bB][01]*[2-9]\d*[lL]\=\>' display + syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*[lL]\=\>' display + syn match pythonBinError '\<0[bB][01]*[2-9]\d*[lL]\=\>' display - syn match pythonFloat '\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>' display - syn match pythonFloat '\<\d\+[eE][+-]\=\d\+[jJ]\=\>' display - syn match pythonFloat '\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=' display + syn match pythonFloat '\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>' display + syn match pythonFloat '\<\d\+[eE][+-]\=\d\+[jJ]\=\>' display + syn match pythonFloat '\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=' display else - syn match pythonOctError '\<0[oO]\=\o*\D\+\d*\>' display - " pythonHexError comes after pythonOctError so that 0xffffl is pythonHexError - syn match pythonHexError '\<0[xX]\x*[g-zG-Z]\x*\>' display - syn match pythonBinError '\<0[bB][01]*\D\+\d*\>' display - - syn match pythonHexNumber '\<0[xX][_0-9a-fA-F]*\x\>' display - syn match pythonOctNumber '\<0[oO][_0-7]*\o\>' display - syn match pythonBinNumber '\<0[bB][_01]*[01]\>' display - - syn match pythonNumberError '\<\d[_0-9]*\D\>' display - syn match pythonNumberError '\<0[_0-9]\+\>' display - syn match pythonNumberError '\<0_x\S*\>' display - syn match pythonNumberError '\<0[bBxXoO][_0-9a-fA-F]*_\>' display - syn match pythonNumberError '\<\d[_0-9]*_\>' display - syn match pythonNumber '\<\d\>' display - syn match pythonNumber '\<[1-9][_0-9]*\d\>' display - syn match pythonNumber '\<\d[jJ]\>' display - syn match pythonNumber '\<[1-9][_0-9]*\d[jJ]\>' display - - syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*\>' display - syn match pythonBinError '\<0[bB][01]*[2-9]\d*\>' display - - syn match pythonFloat '\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=\>' display - syn match pythonFloat '\<\d\%([_0-9]*\d\)\=[eE][+-]\=\d\%([_0-9]*\d\)\=[jJ]\=\>' display - syn match pythonFloat '\<\d\%([_0-9]*\d\)\=\.\d\=\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=' display + syn match pythonOctError '\<0[oO]\=\o*\D\+\d*\>' display + " pythonHexError comes after pythonOctError so that 0xffffl is pythonHexError + syn match pythonHexError '\<0[xX]\x*[g-zG-Z]\x*\>' display + syn match pythonBinError '\<0[bB][01]*\D\+\d*\>' display + + syn match pythonHexNumber '\<0[xX][_0-9a-fA-F]*\x\>' display + syn match pythonOctNumber '\<0[oO][_0-7]*\o\>' display + syn match pythonBinNumber '\<0[bB][_01]*[01]\>' display + + syn match pythonNumberError '\<\d[_0-9]*\D\>' display + syn match pythonNumberError '\<0[_0-9]\+\>' display + syn match pythonNumberError '\<0_x\S*\>' display + syn match pythonNumberError '\<0[bBxXoO][_0-9a-fA-F]*_\>' display + syn match pythonNumberError '\<\d[_0-9]*_\>' display + syn match pythonNumber '\<\d\>' display + syn match pythonNumber '\<[1-9][_0-9]*\d\>' display + syn match pythonNumber '\<\d[jJ]\>' display + syn match pythonNumber '\<[1-9][_0-9]*\d[jJ]\>' display + + syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*\>' display + syn match pythonBinError '\<0[bB][01]*[2-9]\d*\>' display + + syn match pythonFloat '\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=\>' display + syn match pythonFloat '\<\d\%([_0-9]*\d\)\=[eE][+-]\=\d\%([_0-9]*\d\)\=[jJ]\=\>' display + syn match pythonFloat '\<\d\%([_0-9]*\d\)\=\.\d\=\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=' display endif " @@ -336,11 +336,11 @@ endif " if s:Enabled('g:python_highlight_builtin_objs') - syn keyword pythonNone None - syn keyword pythonBoolean True False - syn keyword pythonSingleton Ellipsis NotImplemented - syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ - syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__ + syn keyword pythonNone None + syn keyword pythonBoolean True False + syn keyword pythonSingleton Ellipsis NotImplemented + syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ + syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__ endif " @@ -348,25 +348,25 @@ endif " if s:Enabled('g:python_highlight_builtin_funcs') - let s:funcs_re = '__import__|abs|all|any|bin|callable|chr|classmethod|compile|complex|delattr|dir|divmod|enumerate|eval|filter|format|getattr|globals|hasattr|hash|help|hex|id|input|isinstance|issubclass|iter|len|locals|map|max|memoryview|min|next|oct|open|ord|pow|property|range|repr|reversed|round|setattr|slice|sorted|staticmethod|sum|super|type|vars|zip' - - if s:Python2Syntax() - let s:funcs_re .= '|apply|basestring|buffer|cmp|coerce|execfile|file|intern|long|raw_input|reduce|reload|unichr|unicode|xrange' - if s:Enabled('g:python_print_as_function') - let s:funcs_re .= '|print' + let s:funcs_re = '__import__|abs|all|any|bin|callable|chr|classmethod|compile|complex|delattr|dir|divmod|enumerate|eval|filter|format|getattr|globals|hasattr|hash|help|hex|id|input|isinstance|issubclass|iter|len|locals|map|max|memoryview|min|next|oct|open|ord|pow|property|range|repr|reversed|round|setattr|slice|sorted|staticmethod|sum|super|type|vars|zip' + + if s:Python2Syntax() + let s:funcs_re .= '|apply|basestring|buffer|cmp|coerce|execfile|file|intern|long|raw_input|reduce|reload|unichr|unicode|xrange' + if s:Enabled('g:python_print_as_function') + let s:funcs_re .= '|print' + endif + else + let s:funcs_re .= '|ascii|breakpoint|exec|print' endif - else - let s:funcs_re .= '|ascii|breakpoint|exec|print' - endif - let s:funcs_re = 'syn match pythonBuiltinFunc ''\v\.@' + let s:funcs_re = 'syn match pythonBuiltinFunc ''\v\.@' - if !s:Enabled('g:python_highlight_builtin_funcs_kwarg') - let s:funcs_re .= '\=@!' - endif + if !s:Enabled('g:python_highlight_builtin_funcs_kwarg') + let s:funcs_re .= '\=@!' + endif - execute s:funcs_re . '''' - unlet s:funcs_re + execute s:funcs_re . '''' + unlet s:funcs_re endif " @@ -374,7 +374,7 @@ endif " if s:Enabled('g:python_highlight_builtin_types') - syn match pythonBuiltinType '\v\.@' + syn match pythonBuiltinType '\v\.@' endif @@ -385,14 +385,14 @@ endif if s:Enabled('g:python_highlight_exceptions') let s:exs_re = 'BaseException|Exception|ArithmeticError|LookupError|EnvironmentError|AssertionError|AttributeError|BufferError|EOFError|FloatingPointError|GeneratorExit|IOError|ImportError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|ReferenceError|RuntimeError|StopIteration|SyntaxError|IndentationError|TabError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|VMSError|WindowsError|ZeroDivisionError|Warning|UserWarning|BytesWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning' - if s:Python2Syntax() - let s:exs_re .= '|StandardError' - else - let s:exs_re .= '|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|StopAsyncIteration|ResourceWarning' - endif + if s:Python2Syntax() + let s:exs_re .= '|StandardError' + else + let s:exs_re .= '|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|StopAsyncIteration|ResourceWarning' + endif - execute 'syn match pythonExClass ''\v\.@''' - unlet s:exs_re + execute 'syn match pythonExClass ''\v\.@''' + unlet s:exs_re endif " @@ -400,7 +400,7 @@ endif " if s:Enabled('g:python_highlight_func_calls') - syn match pythonFunctionCall '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\ze\%(\s*(\)' + syn match pythonFunctionCall '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\ze\%(\s*(\)' endif " @@ -408,100 +408,100 @@ endif " if s:Enabled('g:python_slow_sync') - syn sync minlines=2000 + syn sync minlines=2000 else - " This is fast but code inside triple quoted strings screws it up. It - " is impossible to fix because the only way to know if you are inside a - " triple quoted string is to start from the beginning of the file. - syn sync match pythonSync grouphere NONE '):$' - syn sync maxlines=200 + " This is fast but code inside triple quoted strings screws it up. It + " is impossible to fix because the only way to know if you are inside a + " triple quoted string is to start from the beginning of the file. + syn sync match pythonSync grouphere NONE '):$' + syn sync maxlines=200 endif if v:version >= 508 || !exists('did_python_syn_inits') - if v:version <= 508 - let did_python_syn_inits = 1 - command -nargs=+ HiLink hi link - else - command -nargs=+ HiLink hi def link - endif - - HiLink pythonStatement Statement - HiLink pythonRaiseFromStatement Statement - HiLink pythonImport Include - HiLink pythonFunctionContained Function - HiLink pythonFunctionCall Function - HiLink pythonConditional Conditional - HiLink pythonRepeat Repeat - HiLink pythonException Exception - HiLink pythonOperator Operator - - HiLink pythonDecorator Define - HiLink pythonDottedName Function - - HiLink pythonComment Comment - if !s:Enabled('g:python_highlight_file_headers_as_comments') - HiLink pythonCoding Special - HiLink pythonRun Special - endif - HiLink pythonTodo Todo - - HiLink pythonError Error - HiLink pythonIndentError Error - HiLink pythonSpaceError Error - - HiLink pythonString String - HiLink pythonRawString String - HiLink pythonRawEscape Special - - HiLink pythonUniEscape Special - HiLink pythonUniEscapeError Error - - if s:Python2Syntax() - HiLink pythonUniString String - HiLink pythonUniRawString String - HiLink pythonUniRawEscape Special - HiLink pythonUniRawEscapeError Error - else - HiLink pythonBytes String - HiLink pythonRawBytes String - HiLink pythonBytesContent String - HiLink pythonBytesError Error - HiLink pythonBytesEscape Special - HiLink pythonBytesEscapeError Error - HiLink pythonFString String - HiLink pythonRawFString String - HiLink pythonStrInterpRegion Special - endif - - HiLink pythonStrFormatting Special - HiLink pythonStrFormat Special - HiLink pythonStrTemplate Special - - HiLink pythonDocTest Special - HiLink pythonDocTest2 Special - - HiLink pythonNumber Number - HiLink pythonHexNumber Number - HiLink pythonOctNumber Number - HiLink pythonBinNumber Number - HiLink pythonFloat Float - HiLink pythonNumberError Error - HiLink pythonOctError Error - HiLink pythonHexError Error - HiLink pythonBinError Error - - HiLink pythonBoolean Boolean - HiLink pythonNone Constant - HiLink pythonSingleton Constant - - HiLink pythonBuiltinObj Identifier - HiLink pythonBuiltinFunc Function - HiLink pythonBuiltinType Structure - - HiLink pythonExClass Structure - HiLink pythonClassVar Identifier - - delcommand HiLink + if v:version <= 508 + let did_python_syn_inits = 1 + command -nargs=+ HiLink hi link + else + command -nargs=+ HiLink hi def link + endif + + HiLink pythonStatement Statement + HiLink pythonRaiseFromStatement Statement + HiLink pythonImport Include + HiLink pythonFunctionContained Function + HiLink pythonFunctionCall Function + HiLink pythonConditional Conditional + HiLink pythonRepeat Repeat + HiLink pythonException Exception + HiLink pythonOperator Operator + + HiLink pythonDecorator Define + HiLink pythonDottedName Function + + HiLink pythonComment Comment + if !s:Enabled('g:python_highlight_file_headers_as_comments') + HiLink pythonCoding Special + HiLink pythonRun Special + endif + HiLink pythonTodo Todo + + HiLink pythonError Error + HiLink pythonIndentError Error + HiLink pythonSpaceError Error + + HiLink pythonString String + HiLink pythonRawString String + HiLink pythonRawEscape Special + + HiLink pythonUniEscape Special + HiLink pythonUniEscapeError Error + + if s:Python2Syntax() + HiLink pythonUniString String + HiLink pythonUniRawString String + HiLink pythonUniRawEscape Special + HiLink pythonUniRawEscapeError Error + else + HiLink pythonBytes String + HiLink pythonRawBytes String + HiLink pythonBytesContent String + HiLink pythonBytesError Error + HiLink pythonBytesEscape Special + HiLink pythonBytesEscapeError Error + HiLink pythonFString String + HiLink pythonRawFString String + HiLink pythonStrInterpRegion Special + endif + + HiLink pythonStrFormatting Special + HiLink pythonStrFormat Special + HiLink pythonStrTemplate Special + + HiLink pythonDocTest Special + HiLink pythonDocTest2 Special + + HiLink pythonNumber Number + HiLink pythonHexNumber Number + HiLink pythonOctNumber Number + HiLink pythonBinNumber Number + HiLink pythonFloat Float + HiLink pythonNumberError Error + HiLink pythonOctError Error + HiLink pythonHexError Error + HiLink pythonBinError Error + + HiLink pythonBoolean Boolean + HiLink pythonNone Constant + HiLink pythonSingleton Constant + + HiLink pythonBuiltinObj Identifier + HiLink pythonBuiltinFunc Function + HiLink pythonBuiltinType Structure + + HiLink pythonExClass Structure + HiLink pythonClassVar Identifier + + delcommand HiLink endif let b:current_syntax = 'python' From ee2a336f9e3efdb1a11eb64332ab30d38b0a0e51 Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 26 Feb 2020 11:06:11 +0000 Subject: [PATCH 09/19] Fix function call highlighting priority Related to #63 --- syntax/python.vim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 6a602e9..a6fdb48 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -59,6 +59,14 @@ if s:Enabled('g:python_highlight_all') call s:EnableByDefault('g:python_highlight_operators') endif +" +" Function calls +" + +if s:Enabled('g:python_highlight_func_calls') + syn match pythonFunctionCall '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\ze\%(\s*(\)' +endif + " " Keywords " @@ -395,14 +403,6 @@ if s:Enabled('g:python_highlight_exceptions') unlet s:exs_re endif -" -" Function calls -" - -if s:Enabled('g:python_highlight_func_calls') - syn match pythonFunctionCall '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\ze\%(\s*(\)' -endif - " " Misc " From f73fbf0ba68054b44384109c4e0fa4a51eecabbf Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 26 Feb 2020 11:16:24 +0000 Subject: [PATCH 10/19] Fix `PendingDeprecationWarning` typo in tests --- tests/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.py b/tests/test.py index e6e8d1b..246d109 100644 --- a/tests/test.py +++ b/tests/test.py @@ -157,7 +157,7 @@ async def Test TypeError UnboundLocalError UnicodeError UnicodeEncodeError UnicodeDecodeError UnicodeTranslateError ValueError WindowsError ZeroDivisionError -Warning UserWarning DeprecationWarning PendingDepricationWarning SyntaxWarning +Warning UserWarning DeprecationWarning PendingDeprecationWarning SyntaxWarning RuntimeWarning FutureWarning ImportWarning UnicodeWarning # Decorators. From 6ce77d0013690b8b44a8d088ba4b54ba549ae98e Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 26 Feb 2020 20:25:36 +0000 Subject: [PATCH 11/19] Preserve backwards compatibility for `pythonFunction` Related to #63 --- syntax/python.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index a6fdb48..5cac25c 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -73,7 +73,7 @@ endif syn keyword pythonStatement break continue del return pass yield global assert lambda with syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite -syn keyword pythonStatement def class nextgroup=pythonFunctionContained skipwhite +syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite if s:Enabled('g:python_highlight_class_vars') syn keyword pythonClassVar self cls endif @@ -94,12 +94,12 @@ if s:Python2Syntax() endif syn keyword pythonStatement exec syn keyword pythonImport as - syn match pythonFunctionContained '[a-zA-Z_][a-zA-Z0-9_]*' display contained + syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained else syn keyword pythonStatement as nonlocal syn match pythonStatement '\v\.@' - syn match pythonFunctionContained '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained - syn match pythonStatement '\' nextgroup=pythonFunctionContained skipwhite + syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained + syn match pythonStatement '\' nextgroup=pythonFunction skipwhite syn match pythonStatement '\' syn match pythonStatement '\' syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType @@ -428,8 +428,8 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonStatement Statement HiLink pythonRaiseFromStatement Statement HiLink pythonImport Include - HiLink pythonFunctionContained Function - HiLink pythonFunctionCall Function + HiLink pythonFunction Function + HiLink pythonFunctionCall Function HiLink pythonConditional Conditional HiLink pythonRepeat Repeat HiLink pythonException Exception From f351c0d2b1d638b12424e6e7dedb9fe1bbce1f7e Mon Sep 17 00:00:00 2001 From: Sarunas Nejus Date: Tue, 7 Apr 2020 21:35:09 +0100 Subject: [PATCH 12/19] Fix `highlight_builtins` when `highlight_all` isn't set Fixes #66 Closes #67 --- README.md | 2 +- doc/python-syntax.txt | 2 +- syntax/python.vim | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 37062f7..922c335 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ let g:python_highlight_all = 1 | --------------------------------------------- | -------------------------------------------------------------- | ------- | | `g:python_version_2` | Python 2 mode | `0` | | `b:python_version_2` | Python 2 mode (buffer local) | `0` | -| `g:python_highlight_builtins` | Highlight builtin functions and objects | `0` | +| `g:python_highlight_builtins` | Highlight builtin objects, types, and functions | `0` | | `g:python_highlight_builtin_objs` | Highlight builtin objects only | `0` | | `g:python_highlight_builtin_types` | Highlight builtin types only | `0` | | `g:python_highlight_builtin_funcs` | Highlight builtin functions only | `0` | diff --git a/doc/python-syntax.txt b/doc/python-syntax.txt index 8c8f8f2..2a25373 100644 --- a/doc/python-syntax.txt +++ b/doc/python-syntax.txt @@ -57,7 +57,7 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: > Python 2 mode (buffer local) `g:python_highlight_builtins` (default `0`) - Highlight builtin functions and objects + Highlight builtin functions, types, and objects `g:python_highlight_builtin_objs` (default `0`) Highlight builtin objects only diff --git a/syntax/python.vim b/syntax/python.vim index 5cac25c..ba9b464 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -41,11 +41,6 @@ call s:EnableByDefault('g:python_highlight_builtin_funcs_kwarg') if s:Enabled('g:python_highlight_all') call s:EnableByDefault('g:python_highlight_builtins') - if s:Enabled('g:python_highlight_builtins') - call s:EnableByDefault('g:python_highlight_builtin_objs') - call s:EnableByDefault('g:python_highlight_builtin_funcs') - call s:EnableByDefault('g:python_highlight_builtin_types') - endif call s:EnableByDefault('g:python_highlight_exceptions') call s:EnableByDefault('g:python_highlight_string_formatting') call s:EnableByDefault('g:python_highlight_string_format') @@ -59,6 +54,12 @@ if s:Enabled('g:python_highlight_all') call s:EnableByDefault('g:python_highlight_operators') endif +if s:Enabled('g:python_highlight_builtins') + call s:EnableByDefault('g:python_highlight_builtin_objs') + call s:EnableByDefault('g:python_highlight_builtin_funcs') + call s:EnableByDefault('g:python_highlight_builtin_types') +endif + " " Function calls " From c1c5bafb6d2333d25e415eb2ec2d0a54a59a21b4 Mon Sep 17 00:00:00 2001 From: nfnty Date: Sun, 19 Apr 2020 20:33:56 +0100 Subject: [PATCH 13/19] Minor ordering change for `highlight_builtins` Followup to f351c0d2b1d638b12424e6e7dedb9fe1bbce1f7e --- doc/python-syntax.txt | 2 +- syntax/python.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/python-syntax.txt b/doc/python-syntax.txt index 2a25373..59eb0ef 100644 --- a/doc/python-syntax.txt +++ b/doc/python-syntax.txt @@ -57,7 +57,7 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: > Python 2 mode (buffer local) `g:python_highlight_builtins` (default `0`) - Highlight builtin functions, types, and objects + Highlight builtin objects, types, and functions `g:python_highlight_builtin_objs` (default `0`) Highlight builtin objects only diff --git a/syntax/python.vim b/syntax/python.vim index ba9b464..a7f6edc 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -56,8 +56,8 @@ endif if s:Enabled('g:python_highlight_builtins') call s:EnableByDefault('g:python_highlight_builtin_objs') - call s:EnableByDefault('g:python_highlight_builtin_funcs') call s:EnableByDefault('g:python_highlight_builtin_types') + call s:EnableByDefault('g:python_highlight_builtin_funcs') endif " From e82ed75da511a9271f485ae67a0d6b84e2668d61 Mon Sep 17 00:00:00 2001 From: Caleb Donovick Date: Tue, 18 Dec 2018 17:35:56 -0800 Subject: [PATCH 14/19] Enable syntax highlighting in f-strings --- syntax/python.vim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index a7f6edc..63224b1 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -103,7 +103,7 @@ else syn match pythonStatement '\' nextgroup=pythonFunction skipwhite syn match pythonStatement '\' syn match pythonStatement '\' - syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType + syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonFString,pythonRawString,pythonRawFString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType endif @@ -264,8 +264,8 @@ if s:Enabled('g:python_highlight_string_format') syn match pythonStrFormat '{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString else syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString - syn region pythonStrInterpRegion start="{"he=e+1,rs=e+1 end="\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}"hs=s-1,re=s-1 extend contained containedin=pythonFString,pythonRawFString contains=pythonStrInterpRegion,@pythonExpression - syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString,pythonFString,pythonRawFString + syn region pythonStrInterpRegion matchgroup=pythonStrFormat start="\({\)\@=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=\(}\)\@= 508 || !exists('did_python_syn_inits') HiLink pythonBytesEscapeError Error HiLink pythonFString String HiLink pythonRawFString String - HiLink pythonStrInterpRegion Special endif HiLink pythonStrFormatting Special From 082a78ac7d32896928bffa76df7cf2df90a4a12b Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 2 Dec 2020 18:12:54 +0000 Subject: [PATCH 15/19] Fix f-string boundaries and add more tests --- syntax/python.vim | 2 +- tests/test.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 63224b1..cd26b76 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -264,7 +264,7 @@ if s:Enabled('g:python_highlight_string_format') syn match pythonStrFormat '{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString else syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString - syn region pythonStrInterpRegion matchgroup=pythonStrFormat start="\({\)\@=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=\(}\)\@=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" extend contained containedin=pythonFString,pythonRawFString contains=pythonStrInterpRegion,@pythonExpression syn match pythonStrFormat "{{\|}}" contained containedin=pythonFString,pythonRawFString endif endif diff --git a/tests/test.py b/tests/test.py index 246d109..f37aedc 100644 --- a/tests/test.py +++ b/tests/test.py @@ -244,8 +244,11 @@ async def Test f"{var}...{arr[123]} normal {var['{'] // 0xff} \"xzcb\" 'xzcb' {var['}'] + 1} text" f"{expr1 if True or False else expr2} {None} wow {','.join(c.lower() for c in 'asdf')}" f"hello {expr:.2f} yes {(lambda: 0b1)():#03x} lol {var!r}" -f'brackets: {{ 1 + 2 }} and {{{{ 3 + 4 }}}}' +f'brackets: {{{ 1 + 2 }}} and {{{{ 3 + 4 }}}}' fr'this {that}' +f"{f'{1+1}'}" +'{{ }}' +f"{"{test}"}" # FIXME: syntax error that should not be highlighted # Doctests. From 2ccfb142e77c20454d0debbc5c3d2f07513bf709 Mon Sep 17 00:00:00 2001 From: fishsouprecipe Date: Fri, 25 Sep 2020 09:24:21 +0300 Subject: [PATCH 16/19] Add `mcs` to class variables Closes #74 --- README.md | 4 ++-- doc/python-syntax.txt | 4 ++-- syntax/python.vim | 2 +- tests/test.py | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 922c335..382472e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Features * New exceptions and builtins * Doctests * `@decorator` syntax - * Class variables such as `self` and `cls` + * Class variables such as `self`, `cls`, and `mcs` * Operators * Highlighting of the following errors: * Invalid symbols in source file @@ -72,7 +72,7 @@ let g:python_highlight_all = 1 | `g:python_highlight_space_errors` | Highlight trailing spaces | `0` | | `g:python_highlight_doctests` | Highlight doc-tests | `0` | | `g:python_highlight_func_calls` | Highlight functions calls | `0` | -| `g:python_highlight_class_vars` | Highlight class variables `self` and `cls` | `0` | +| `g:python_highlight_class_vars` | Highlight class variables `self`, `cls`, and `mcs` | `0` | | `g:python_highlight_operators` | Highlight all operators | `0` | | `g:python_highlight_all` | Enable all highlight options above, except for previously set. | `0` | | `g:python_highlight_file_headers_as_comments` | Highlight shebang and coding headers as comments | `0` | diff --git a/doc/python-syntax.txt b/doc/python-syntax.txt index 59eb0ef..79c569e 100644 --- a/doc/python-syntax.txt +++ b/doc/python-syntax.txt @@ -21,7 +21,7 @@ Features * New exceptions and builtins * Doctests * `@decorator` syntax - * Class variables such as `self` and `cls` + * Class variables such as `self`, `cls`, and `mcs` * Operators * Highlighting of the following errors: * Invalid symbols in source file @@ -96,7 +96,7 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: > Highlight functions calls `g:python_highlight_class_vars` (default `0`) - Highlight class variables `self` and `cls` + Highlight class variables `self`, `cls`, and `mcs` `g:python_highlight_operators` (default `0`) Highlight all operators diff --git a/syntax/python.vim b/syntax/python.vim index cd26b76..3ff422f 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -76,7 +76,7 @@ syn keyword pythonStatement break continue del return pass yield global asse syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite if s:Enabled('g:python_highlight_class_vars') - syn keyword pythonClassVar self cls + syn keyword pythonClassVar self cls mcs endif syn keyword pythonRepeat for while syn keyword pythonConditional if elif else diff --git a/tests/test.py b/tests/test.py index f37aedc..20555a4 100644 --- a/tests/test.py +++ b/tests/test.py @@ -11,6 +11,8 @@ with break continue del return pass raise global assert lambda yield for while if elif else import as try except finally +self cls mcs + from test import var as name raise Exception from ex From 0ad21fd728a486535ebcc8667cf77675b3f9b337 Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 2 Dec 2020 19:57:28 +0000 Subject: [PATCH 17/19] Highlight class variables inside f-strings Fixes #56 --- syntax/python.vim | 2 +- tests/test.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 3ff422f..80135a1 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -103,7 +103,7 @@ else syn match pythonStatement '\' nextgroup=pythonFunction skipwhite syn match pythonStatement '\' syn match pythonStatement '\' - syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonFString,pythonRawString,pythonRawFString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType + syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonFString,pythonRawString,pythonRawFString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType,pythonClassVar endif diff --git a/tests/test.py b/tests/test.py index 20555a4..2880a13 100644 --- a/tests/test.py +++ b/tests/test.py @@ -251,6 +251,7 @@ async def Test f"{f'{1+1}'}" '{{ }}' f"{"{test}"}" # FIXME: syntax error that should not be highlighted +f'{self.__name__} # Doctests. From 83d4c63f772c00d8a2dfd44673d7c75999b4ef91 Mon Sep 17 00:00:00 2001 From: koka Date: Sat, 8 Jul 2017 22:52:22 +0900 Subject: [PATCH 18/19] Implement python class name highlighting Fixes #18 Closes #30 --- syntax/python.vim | 5 ++++- tests/test.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 80135a1..86b22c1 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -74,7 +74,8 @@ endif syn keyword pythonStatement break continue del return pass yield global assert lambda with syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite -syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite +syn keyword pythonStatement def nextgroup=pythonFunction skipwhite +syn keyword pythonStatement class nextgroup=pythonClass skipwhite if s:Enabled('g:python_highlight_class_vars') syn keyword pythonClassVar self cls mcs endif @@ -100,6 +101,7 @@ else syn keyword pythonStatement as nonlocal syn match pythonStatement '\v\.@' syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained + syn match pythonClass '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained syn match pythonStatement '\' nextgroup=pythonFunction skipwhite syn match pythonStatement '\' syn match pythonStatement '\' @@ -499,6 +501,7 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonBuiltinType Structure HiLink pythonExClass Structure + HiLink pythonClass Structure HiLink pythonClassVar Identifier delcommand HiLink diff --git a/tests/test.py b/tests/test.py index 2880a13..61b91a1 100644 --- a/tests/test.py +++ b/tests/test.py @@ -26,9 +26,13 @@ def functionname test.functionname() test.functionname () class Classname +class classname +class classname_cls def функция функция() class Класс +class класс + # Keywords: Python 2 From 2cc00ba72929ea5f9456a26782db57fb4cc56a65 Mon Sep 17 00:00:00 2001 From: Joakker Date: Sun, 13 Dec 2020 23:07:57 -0300 Subject: [PATCH 19/19] Add walrus operator Closes #77 --- syntax/python.vim | 2 +- tests/test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 86b22c1..2524aba 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -114,7 +114,7 @@ endif " syn keyword pythonOperator and in is not or if s:Enabled('g:python_highlight_operators') - syn match pythonOperator '\V=\|-\|+\|*\|@\|/\|%\|&\||\|^\|~\|<\|>\|!=' + syn match pythonOperator '\V=\|-\|+\|*\|@\|/\|%\|&\||\|^\|~\|<\|>\|!=\|:=' endif syn match pythonError '[$?]\|\([-+@%&|^~]\)\1\{1,}\|\([=*/<>]\)\2\{2,}\|\([+@/%&|^~<>]\)\3\@![-+*@/%&|^~<>]\|\*\*[*@/%&|^<>]\|=[*@/%&|^<>]\|-[+*@/%&|^~<]\|[]\+=\{2,}\|!\{2,}=\+' display diff --git a/tests/test.py b/tests/test.py index 61b91a1..c0f81ac 100644 --- a/tests/test.py +++ b/tests/test.py @@ -182,7 +182,7 @@ async def Test < <= == != >= > = =- =+ =~ --= += *= **= @= /= //= %= +-= += *= **= @= /= //= %= := &= |= ^= ~= <<= >>= ->