diff --git a/syntax/python.vim b/syntax/python.vim index 913da9d..d330b7e 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -1,17 +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 -elseif exists('b:current_syntax') +if exists('b:current_syntax') finish endif -" -" Commands -" -command! -buffer Python2Syntax let b:python_version_2 = 1 | let &syntax=&syntax -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) @@ -24,14 +16,6 @@ function! s:Enabled(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') -endfunction - " " Default options " @@ -55,6 +39,71 @@ if s:Enabled('g:python_highlight_all') call s:EnableByDefault('g:python_print_as_function') call s:EnableByDefault('g:python_highlight_class_vars') call s:EnableByDefault('g:python_highlight_operators') + call s:EnableByDefault('g:python_highlight_type_annotations') +endif + +" +" Builtin objects and types +" + +if s:Enabled('g:python_highlight_builtin_objs') + syn keyword pythonNone None + syn keyword pythonBoolean True False + syn keyword pythonBuiltinObj Ellipsis NotImplemented + syntax match pythonBuiltinType '\v<%(object|bool|int|float|tuple|str|list|dict|set|frozenset|bytearray|bytes)>' + syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ + syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__ +endif + + +if s:Enabled('g:python_highlight_type_annotations') + " These are derived from the lists found in python typing.py + " Super-special typing primitives. + syntax match pythonBuiltinType '\v<%(Any|Callable|ClassVar|Generic|Optional|Tuple|Type|TypeVar|Union)>' + + " ABCs (from collections.abc). + syntax match pythonBuiltinType '\v<%(AbstractSet|ByteString|Container|ContextManager|Hashable|ItemsView|Iterable|Iterator|KeysView|Mapping|MappingView|MutableMapping|MutableSequence|MutableSet|Sequence|Sized|ValuesView|Awaitable|AsyncIterator|AsyncIterable|Coroutine|Collection|AsyncGenerator|AsyncContextManager)>' + + " Structural checks, a.k.a. protocols. + syntax match pythonBuiltinType '\v<%(Reversible|SupportsAbs|SupportsBytes|SupportsComplex|SupportsFloat|SupportsInt|SupportsRound)>' + + " Concrete collection types. + syntax match pythonBuiltinType '\v<%(Counter|Deque|Dict|DefaultDict|List|Set|FrozenSet|NamedTuple|Generator)>' + + " One-off things. + syntax match pythonBuiltinType '\v<%(AnyStr|cast|get_type_hints|NewType|no_type_check|no_type_check_decorator|NoReturn|overload|Text|TYPE_CHECKING)>' +endif + +" +" Builtin functions +" + +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' + + let s:funcs_re .= '|ascii|exec|print' + + let s:funcs_re = 'syn match pythonBuiltinFunc ''\v\.@' + + if !s:Enabled('g:python_highlight_builtin_funcs_kwarg') + let s:funcs_re .= '\=@!' + endif + + execute s:funcs_re . '''' + unlet s:funcs_re +endif + +" +" Builtin exceptions and warnings +" + +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 .= '|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|StopAsyncIteration|ResourceWarning' + + execute 'syn match pythonExClass ''\v\.@''' + unlet s:exs_re endif " @@ -78,23 +127,20 @@ syn match pythonRaiseFromStatement '\' 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 pythonFunction '[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 pythonStatement '\' - syn match pythonStatement '\' - syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonBuiltinObj,pythonBuiltinFunc -endif +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 pythonStatement '\' +syn match pythonStatement '\' +syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonBuiltinObj,pythonBuiltinFunc + +" +" Code blocks +" +syntax match pythonDictColon contained /:/ +syntax match pythonDictComma contained /,/ " " Operators @@ -105,16 +151,13 @@ if s:Enabled('g:python_highlight_operators') endif syn match pythonError '[$?]\|\([-+@%&|^~]\)\1\{1,}\|\([=*/<>]\)\2\{2,}\|\([+@/%&|^~<>]\)\3\@![-+*@/%&|^~<>]\|\*\*[*@/%&|^<>]\|=[*@/%&|^<>]\|-[+*@/%&|^~<]\|[]\+=\{2,}\|!\{2,}=\+' display + " -" Decorators (new in Python 2.4) +" Decorators " 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 -else - syn match pythonDottedName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*' display contained -endif +syn match pythonDottedName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*' display contained syn match pythonDot '\.' display containedin=pythonDottedName " @@ -149,22 +192,13 @@ endif " Strings " -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 -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 region pythonBytes start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent + syn region pythonBytes start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent + syn region pythonBytes start=+[bB]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError + syn region pythonBytes start=+[bB]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError syn match pythonBytesError '.\+' display contained syn match pythonBytesContent '[\u0000-\u00ff]\+' display contained contains=pythonBytesEscape,pythonBytesEscapeError -endif syn match pythonBytesEscape +\\[abfnrtv'"\\]+ display contained syn match pythonBytesEscape '\\\o\o\=\o\=' display contained @@ -180,95 +214,53 @@ syn match pythonUniEscapeError '\\U\x\{,7}\X' display contained 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 -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 +" Python 3 strings + syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError + syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError 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=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError + syn region pythonFString start=+[fF]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError 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 -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 -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 +" Python raw strings + syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape + syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape 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=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape + syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape 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=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape + syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape 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 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 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 endif if s:Enabled('g:python_highlight_doctests') @@ -281,109 +273,32 @@ endif " Numbers (ints, longs, floats, complex) " -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 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 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 -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 -endif - -" -" Builtin objects and types -" - -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 pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ - syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__ -endif - -" -" Builtin functions -" - -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' +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 - 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|exec|print' - endif +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 - let s:funcs_re = 'syn match pythonBuiltinFunc ''\v\.@' +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 - if !s:Enabled('g:python_highlight_builtin_funcs_kwarg') - let s:funcs_re .= '\=@!' - endif +syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*\>' display +syn match pythonBinError '\<0[bB][01]*[2-9]\d*\>' display - execute s:funcs_re . '''' - unlet s:funcs_re -endif +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 -" -" Builtin exceptions and warnings -" - -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' - - 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 -endif if s:Enabled('g:python_slow_sync') syn sync minlines=2000 @@ -407,11 +322,13 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonRaiseFromStatement Statement HiLink pythonImport Include HiLink pythonFunction Function + HiLink pythonKeywordArgument Argument HiLink pythonConditional Conditional HiLink pythonRepeat Repeat HiLink pythonException Exception HiLink pythonOperator Operator + HiLink pythonDecorator Define HiLink pythonDottedName Function HiLink pythonDot Normal @@ -434,12 +351,6 @@ if v:version >= 508 || !exists('did_python_syn_inits') 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 @@ -449,7 +360,6 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonFString String HiLink pythonRawFString String HiLink pythonStrInterpRegion Special - endif HiLink pythonStrFormatting Special HiLink pythonStrFormat Special @@ -472,6 +382,7 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonNone Constant HiLink pythonBuiltinObj Structure + HiLink pythonBuiltinType Type HiLink pythonBuiltinFunc Function HiLink pythonExClass Structure