From aaf6ad6aff7c2ed9c76184c667053c018d77e868 Mon Sep 17 00:00:00 2001 From: Martin Domke Date: Wed, 27 Apr 2022 09:48:50 +0200 Subject: [PATCH 1/7] Add support for match expression This is based on the work of [@g15ecb](https://github.com/g15ecb) https://github.com/g15ecb/python-syntax/commit/988efe9edcfeed9e762102fcb315a4fd47db4c00 --- syntax/python.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 2524aba..23388bc 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -82,6 +82,7 @@ endif syn keyword pythonRepeat for while syn keyword pythonConditional if elif else syn keyword pythonException try except finally +syn keyword pythonMatch match case " The standard pyrex.vim unconditionally removes the pythonInclude group, so " we provide a dummy group here to avoid crashing pyrex.vim. syn keyword pythonInclude import @@ -105,7 +106,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,pythonClassVar + syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonMatch,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonFString,pythonRawString,pythonRawFString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType,pythonClassVar endif @@ -434,6 +435,7 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonFunction Function HiLink pythonFunctionCall Function HiLink pythonConditional Conditional + HiLink pythonMatch Conditional HiLink pythonRepeat Repeat HiLink pythonException Exception HiLink pythonOperator Operator From 907edc6d1c5154d9c6e90acf775433d95ea2f007 Mon Sep 17 00:00:00 2001 From: Anton Abrosimov Date: Thu, 17 Nov 2022 11:27:11 +0300 Subject: [PATCH 2/7] Add new exceptions --- syntax/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 23388bc..3acc9ec 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -400,7 +400,7 @@ if s:Enabled('g:python_highlight_exceptions') 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' + let s:exs_re .= '|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|StopAsyncIteration|ResourceWarning|ModuleNotFoundError|BaseExceptionGroup|ExceptionGroup|RecursionError|EncodingWarning' endif execute 'syn match pythonExClass ''\v\.@''' From 48cd0ab17f8b7af4de8f7edbc31eb5b3156b5959 Mon Sep 17 00:00:00 2001 From: Anton Abrosimov Date: Thu, 17 Nov 2022 11:28:53 +0300 Subject: [PATCH 3/7] Split FIXME, TODO, XXX --- syntax/python.vim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 3acc9ec..2acf8c5 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -135,12 +135,14 @@ syn match pythonDot '\.' display containedin=pythonDottedName " Comments " -syn match pythonComment '#.*$' display contains=pythonTodo,@Spell +syn match pythonComment '#.*$' display contains=pythonTodo,pythonFixme,pythonXXX,@Spell if !s:Enabled('g:python_highlight_file_headers_as_comments') syn match pythonRun '\%^#!.*$' syn match pythonCoding '\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$' endif -syn keyword pythonTodo TODO FIXME XXX contained +syn keyword pythonTodo TODO contained +syn keyword pythonFixme FIXME contained +syn keyword pythonXXX XXX contained " " Errors @@ -449,6 +451,8 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonRun Special endif HiLink pythonTodo Todo + HiLink pythonFixme Todo + HiLink pythonXXX Todo HiLink pythonError Error HiLink pythonIndentError Error From 57cbc9630ec8a3391501b2aef655e8aef38d1a2a Mon Sep 17 00:00:00 2001 From: Anton Abrosimov Date: Thu, 17 Nov 2022 11:45:00 +0300 Subject: [PATCH 4/7] Add brackets highlight --- syntax/python.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/syntax/python.vim b/syntax/python.vim index 2acf8c5..0866a14 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -52,6 +52,7 @@ if s:Enabled('g:python_highlight_all') 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_brackets') endif if s:Enabled('g:python_highlight_builtins') @@ -89,6 +90,9 @@ syn keyword pythonInclude import syn keyword pythonImport import syn match pythonRaiseFromStatement '\' syn match pythonImport '^\s*\zsfrom\>' +if s:Enabled('g:python_highlight_brackets') + syn match pythonBrackets '[()\[\]{},:]\|->' +endif if s:Python2Syntax() From d9616c9bbee4c948899639a1bd835e6a917b4433 Mon Sep 17 00:00:00 2001 From: Anton Abrosimov Date: Thu, 17 Nov 2022 11:46:02 +0300 Subject: [PATCH 5/7] Add logger highlight --- syntax/python.vim | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/syntax/python.vim b/syntax/python.vim index 0866a14..8e6165a 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -52,6 +52,7 @@ if s:Enabled('g:python_highlight_all') 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_logger') call s:EnableByDefault('g:python_highlight_brackets') endif @@ -90,6 +91,9 @@ syn keyword pythonInclude import syn keyword pythonImport import syn match pythonRaiseFromStatement '\' syn match pythonImport '^\s*\zsfrom\>' +if s:Enabled('g:python_highlight_logger') + syn keyword pythonLog log _log __log LOG _LOG __LOG logger +endif if s:Enabled('g:python_highlight_brackets') syn match pythonBrackets '[()\[\]{},:]\|->' endif @@ -514,6 +518,10 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonClass Structure HiLink pythonClassVar Identifier + if s:Enabled('g:python_highlight_logger') + HiLink pythonLog Identifier + endif + delcommand HiLink endif From 5f3ce6a6fe78f08c2f5a76f67eff5c0376d91882 Mon Sep 17 00:00:00 2001 From: Anton Abrosimov Date: Thu, 17 Nov 2022 11:47:02 +0300 Subject: [PATCH 6/7] Highlight raise as exception --- syntax/python.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 8e6165a..28d4c74 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -75,7 +75,6 @@ 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 nextgroup=pythonFunction skipwhite syn keyword pythonStatement class nextgroup=pythonClass skipwhite if s:Enabled('g:python_highlight_class_vars') @@ -83,8 +82,9 @@ if s:Enabled('g:python_highlight_class_vars') endif syn keyword pythonRepeat for while syn keyword pythonConditional if elif else -syn keyword pythonException try except finally syn keyword pythonMatch match case +syn keyword pythonException try except finally raise +syn keyword pythonException raise nextgroup=pythonExClass skipwhite " The standard pyrex.vim unconditionally removes the pythonInclude group, so " we provide a dummy group here to avoid crashing pyrex.vim. syn keyword pythonInclude import From 557e516ac50ec93b8408c928e4116c5b3869251a Mon Sep 17 00:00:00 2001 From: Anton Abrosimov Date: Thu, 17 Nov 2022 13:27:01 +0300 Subject: [PATCH 7/7] Add docstrings highlight --- syntax/python.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/syntax/python.vim b/syntax/python.vim index 28d4c74..5bd4ea4 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -45,6 +45,7 @@ if s:Enabled('g:python_highlight_all') 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_string_doc') call s:EnableByDefault('g:python_highlight_indent_errors') call s:EnableByDefault('g:python_highlight_space_errors') call s:EnableByDefault('g:python_highlight_doctests') @@ -301,6 +302,17 @@ if s:Enabled('g:python_highlight_doctests') syn region pythonDocTest2 start='^\s*>>>' skip=+\\"+ end=+"""+he=s-1 end='^\s*$' contained endif +if s:Enabled('g:python_highlight_string_doc') + syn match pythonColon ':' nextgroup=pythonDocString skipempty + syn match pythonStartFile +\%^+ nextgroup=pythonDocString skipempty + syn region pythonDocString start=+^\s*[rRfFbB]\='''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell + syn region pythonDocString start=+^\s*[rRfFbB]\="""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell + syn region pythonString start=+^\s*[rRfFbB]\='''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell + syn region pythonString start=+^\s*[rRfFbB]\="""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell + syn region pythonDocString start=+\%^\s*[rRfFbB]\='''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell + syn region pythonDocString start=+\%^\s*[rRfFbB]\="""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell +endif + " " Numbers (ints, longs, floats, complex) " @@ -492,6 +504,7 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonStrFormatting Special HiLink pythonStrFormat Special HiLink pythonStrTemplate Special + HiLink pythonDocString Comment HiLink pythonDocTest Special HiLink pythonDocTest2 Special