Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new exceptions #93

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions syntax/python.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ 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')
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_logger')
call s:EnableByDefault('g:python_highlight_brackets')
endif

if s:Enabled('g:python_highlight_builtins')
Expand All @@ -73,21 +76,28 @@ 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')
syn keyword pythonClassVar self cls mcs
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
syn keyword pythonImport import
syn match pythonRaiseFromStatement '\<from\>'
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


if s:Python2Syntax()
Expand All @@ -105,7 +115,7 @@ else
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunction skipwhite
syn match pythonStatement '\<async\s\+with\>'
syn match pythonStatement '\<async\s\+for\>'
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


Expand Down Expand Up @@ -134,12 +144,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
Expand Down Expand Up @@ -290,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)
"
Expand Down Expand Up @@ -399,7 +422,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\.@<!\zs<%(' . s:exs_re . ')>'''
Expand Down Expand Up @@ -434,6 +457,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
Expand All @@ -447,6 +471,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
Expand Down Expand Up @@ -478,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
Expand All @@ -504,6 +531,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

Expand Down