2015-07-18 17:05:45 -04:00
|
|
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'python') == -1
|
|
|
|
|
2013-09-12 10:23:36 -04:00
|
|
|
" Vim syntax file
|
|
|
|
"
|
|
|
|
" Based on python.vim (from Vim 6.1 distribution)
|
|
|
|
" by Neil Schemenauer <nas@python.ca>
|
|
|
|
"
|
2014-04-14 19:18:16 -04:00
|
|
|
" Notes Armin:
|
|
|
|
"
|
|
|
|
" This version of the syntax file works better for 2.x and 3.x without
|
|
|
|
" having to switch modes.
|
|
|
|
"
|
2013-09-12 10:23:36 -04:00
|
|
|
" Thanks:
|
|
|
|
"
|
|
|
|
" Jeroen Ruigrok van der Werven
|
2014-04-14 19:18:16 -04:00
|
|
|
" for the idea of highlighting for erroneous operators
|
2013-09-12 10:23:36 -04:00
|
|
|
" Pedro Algarvio
|
|
|
|
" for the patch to enable spell checking only for the right spots
|
|
|
|
" (strings and comments)
|
|
|
|
|
|
|
|
"
|
|
|
|
" Options:
|
|
|
|
"
|
|
|
|
" For set option do: let OPTION_NAME = 1
|
|
|
|
" For clear option do: let OPTION_NAME = 0
|
|
|
|
"
|
|
|
|
" Option names:
|
|
|
|
"
|
2014-04-14 19:18:16 -04:00
|
|
|
" For highlight builtin functions:
|
2013-09-12 10:23:36 -04:00
|
|
|
" python_highlight_builtins
|
|
|
|
"
|
|
|
|
" For highlight standard exceptions:
|
|
|
|
" python_highlight_exceptions
|
|
|
|
"
|
|
|
|
" For highlight string formatting:
|
|
|
|
" python_highlight_string_formatting
|
|
|
|
"
|
|
|
|
" For highlight indentation errors:
|
|
|
|
" python_highlight_indent_errors
|
|
|
|
"
|
|
|
|
" For highlight trailing spaces:
|
|
|
|
" python_highlight_space_errors
|
|
|
|
"
|
|
|
|
" For highlight doc-tests:
|
|
|
|
" python_highlight_doctests
|
|
|
|
"
|
2014-04-14 19:18:16 -04:00
|
|
|
" If you want all possible Python highlighting:
|
2013-09-12 10:23:36 -04:00
|
|
|
" (This option not override previously set options)
|
2014-04-14 19:18:16 -04:00
|
|
|
" python_highlight_all
|
2013-09-12 10:23:36 -04:00
|
|
|
"
|
|
|
|
" For fast machines:
|
|
|
|
" python_slow_sync
|
|
|
|
"
|
|
|
|
|
|
|
|
" For version 5.x: Clear all syntax items
|
|
|
|
" For version 6.x: Quit when a syntax file was already loaded
|
|
|
|
if version < 600
|
|
|
|
syntax clear
|
|
|
|
elseif exists("b:current_syntax")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists("python_highlight_all") && python_highlight_all != 0
|
|
|
|
" Not override previously set options
|
|
|
|
if !exists("python_highlight_builtins")
|
2014-04-14 19:18:16 -04:00
|
|
|
let python_highlight_builtins = 1
|
2013-09-12 10:23:36 -04:00
|
|
|
endif
|
|
|
|
if !exists("python_highlight_exceptions")
|
|
|
|
let python_highlight_exceptions = 1
|
|
|
|
endif
|
|
|
|
if !exists("python_highlight_string_formatting")
|
|
|
|
let python_highlight_string_formatting = 1
|
|
|
|
endif
|
|
|
|
if !exists("python_highlight_indent_errors")
|
|
|
|
let python_highlight_indent_errors = 1
|
|
|
|
endif
|
|
|
|
if !exists("python_highlight_space_errors")
|
|
|
|
let python_highlight_space_errors = 1
|
|
|
|
endif
|
|
|
|
if !exists("python_highlight_doctests")
|
|
|
|
let python_highlight_doctests = 1
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Keywords
|
|
|
|
syn keyword pythonStatement break continue del
|
|
|
|
syn keyword pythonStatement exec return
|
|
|
|
syn keyword pythonStatement pass raise
|
|
|
|
syn keyword pythonStatement global assert
|
|
|
|
syn keyword pythonStatement lambda yield
|
2015-12-06 05:31:38 -05:00
|
|
|
syn keyword pythonStatement async await
|
2014-04-14 19:18:16 -04:00
|
|
|
syn keyword pythonStatement with nonlocal True False None
|
2013-09-12 10:23:36 -04:00
|
|
|
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
|
|
|
|
syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained
|
|
|
|
syn keyword pythonRepeat for while
|
|
|
|
syn keyword pythonConditional if elif else
|
2014-04-14 19:18:16 -04:00
|
|
|
syn keyword pythonImport import from as
|
2013-09-12 10:23:36 -04:00
|
|
|
syn keyword pythonException try except finally
|
|
|
|
syn keyword pythonOperator and in is not or
|
|
|
|
|
2014-04-14 19:18:16 -04:00
|
|
|
" Print keyword but only if not used as function
|
2016-12-20 14:57:20 -05:00
|
|
|
syn match pythonStatement "\<print\>\((\|,\|*=\)\@!" display
|
2013-09-12 10:23:36 -04:00
|
|
|
|
|
|
|
" Decorators (new in Python 2.4)
|
2014-04-14 19:18:16 -04:00
|
|
|
syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite
|
2013-09-12 10:23:36 -04:00
|
|
|
|
|
|
|
" Comments
|
|
|
|
syn match pythonComment "#.*$" display contains=pythonTodo,@Spell
|
|
|
|
syn match pythonRun "\%^#!.*$"
|
|
|
|
syn match pythonCoding "\%^.*\(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
|
|
|
|
syn keyword pythonTodo TODO FIXME XXX contained
|
|
|
|
|
|
|
|
" Errors
|
|
|
|
syn match pythonError "\<\d\+\D\+\>" display
|
|
|
|
syn match pythonError "[$?]" display
|
2014-04-14 19:18:16 -04:00
|
|
|
syn match pythonError "[-+&|]\{2,}" display
|
2013-09-12 10:23:36 -04:00
|
|
|
syn match pythonError "[=]\{3,}" display
|
|
|
|
|
|
|
|
" TODO: Mixing spaces and tabs also may be used for pretty formatting multiline
|
|
|
|
" statements. For now I don't know how to work around this.
|
|
|
|
if exists("python_highlight_indent_errors") && python_highlight_indent_errors != 0
|
|
|
|
syn match pythonIndentError "^\s*\( \t\|\t \)\s*\S"me=e-1 display
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Trailing space errors
|
|
|
|
if exists("python_highlight_space_errors") && python_highlight_space_errors != 0
|
|
|
|
syn match pythonSpaceError "\s\+$" display
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Strings
|
2014-04-14 19:18:16 -04:00
|
|
|
syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
|
|
|
|
syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
|
|
|
|
syn region pythonString start=+"""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
|
|
syn region pythonString start=+'''+ end=+'''+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
2013-09-12 10:23:36 -04:00
|
|
|
|
|
|
|
syn match pythonEscape +\\[abfnrtv'"\\]+ display contained
|
|
|
|
syn match pythonEscape "\\\o\o\=\o\=" display contained
|
|
|
|
syn match pythonEscapeError "\\\o\{,2}[89]" display contained
|
|
|
|
syn match pythonEscape "\\x\x\{2}" display contained
|
|
|
|
syn match pythonEscapeError "\\x\x\=\X" display contained
|
|
|
|
syn match pythonEscape "\\$"
|
|
|
|
|
2014-04-14 19:18:16 -04:00
|
|
|
" Byte-Strings
|
|
|
|
syn region pythonBString start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBEscape,pythonBEscapeError,@Spell
|
|
|
|
syn region pythonBString start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBEscape,pythonBEscapeError,@Spell
|
|
|
|
syn region pythonBString start=+[bB]"""+ end=+"""+ keepend contains=pythonBEscape,pythonBEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
|
|
syn region pythonBString start=+[bB]'''+ end=+'''+ keepend contains=pythonBEscape,pythonBEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
|
|
|
|
|
|
|
syn match pythonBEscape +\\[abfnrtv'"\\]+ display contained
|
|
|
|
syn match pythonBEscape "\\\o\o\=\o\=" display contained
|
|
|
|
syn match pythonBEscapeError "\\\o\{,2}[89]" display contained
|
|
|
|
syn match pythonBEscape "\\x\x\{2}" display contained
|
|
|
|
syn match pythonBEscapeError "\\x\x\=\X" display contained
|
|
|
|
syn match pythonBEscape "\\$"
|
|
|
|
|
2013-09-12 10:23:36 -04:00
|
|
|
" Unicode strings
|
|
|
|
syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
|
|
|
|
syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
|
|
|
|
syn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
|
|
syn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
|
|
|
|
|
|
|
syn match pythonUniEscape "\\u\x\{4}" display contained
|
|
|
|
syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained
|
|
|
|
syn match pythonUniEscape "\\U\x\{8}" display contained
|
|
|
|
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
|
|
|
|
|
|
|
|
" Raw strings
|
|
|
|
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]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
|
|
|
|
syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
|
|
|
|
|
|
|
syn match pythonRawEscape +\\['"]+ display transparent contained
|
|
|
|
|
|
|
|
" 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]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
|
|
syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
|
|
|
|
|
|
|
syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained
|
|
|
|
syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained
|
|
|
|
|
|
|
|
if exists("python_highlight_string_formatting") && python_highlight_string_formatting != 0
|
|
|
|
" String formatting
|
2014-04-14 19:18:16 -04:00
|
|
|
syn match pythonStrFormat "%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonBString,pythonUniString,pythonRawString,pythonUniRawString
|
|
|
|
syn match pythonStrFormat "%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonBString,pythonUniString,pythonRawString,pythonUniRawString
|
2013-09-12 10:23:36 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if exists("python_highlight_doctests") && python_highlight_doctests != 0
|
|
|
|
" DocTests
|
|
|
|
syn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained
|
|
|
|
syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Numbers (ints, longs, floats, complex)
|
|
|
|
syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" display
|
2014-04-14 19:18:16 -04:00
|
|
|
syn match pythonHexNumber "\<0[xX]\>" display
|
2013-09-12 10:23:36 -04:00
|
|
|
syn match pythonNumber "\<\d\+[lLjJ]\=\>" 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
|
|
|
|
|
2014-04-14 19:18:16 -04:00
|
|
|
syn match pythonOctalError "\<0\o*[89]\d*[lL]\=\>" display
|
|
|
|
syn match pythonHexError "\<0[xX]\X\+[lL]\=\>" display
|
2013-09-12 10:23:36 -04:00
|
|
|
|
2014-04-14 19:18:16 -04:00
|
|
|
if exists("python_highlight_builtins") && python_highlight_builtins != 0
|
|
|
|
" Builtin functions, types and objects
|
|
|
|
syn keyword pythonBuiltinObj Ellipsis NotImplemented
|
2013-09-12 10:23:36 -04:00
|
|
|
|
|
|
|
syn keyword pythonBuiltinFunc __import__ abs all any apply
|
2015-12-06 05:31:38 -05:00
|
|
|
syn keyword pythonBuiltinFunc basestring bool buffer bytearray bytes callable
|
2013-09-12 10:23:36 -04:00
|
|
|
syn keyword pythonBuiltinFunc chr classmethod cmp coerce compile complex
|
|
|
|
syn keyword pythonBuiltinFunc delattr dict dir divmod enumerate eval
|
2014-04-14 19:18:16 -04:00
|
|
|
syn keyword pythonBuiltinFunc execfile file filter float frozenset getattr
|
|
|
|
syn keyword pythonBuiltinfunc globals hasattr hash help hex id
|
2013-09-12 10:23:36 -04:00
|
|
|
syn keyword pythonBuiltinFunc input int intern isinstance
|
|
|
|
syn keyword pythonBuiltinFunc issubclass iter len list locals long map max
|
2014-04-14 19:18:16 -04:00
|
|
|
syn keyword pythonBuiltinFunc min object oct open ord pow property range
|
2013-09-12 10:23:36 -04:00
|
|
|
syn keyword pythonBuiltinFunc raw_input reduce reload repr
|
2014-04-14 19:18:16 -04:00
|
|
|
syn keyword pythonBuiltinFunc reversed round set setattr
|
2013-09-12 10:23:36 -04:00
|
|
|
syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple
|
|
|
|
syn keyword pythonBuiltinFunc type unichr unicode vars xrange zip
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists("python_highlight_exceptions") && python_highlight_exceptions != 0
|
|
|
|
" Builtin exceptions and warnings
|
|
|
|
syn keyword pythonExClass BaseException
|
|
|
|
syn keyword pythonExClass Exception StandardError ArithmeticError
|
|
|
|
syn keyword pythonExClass LookupError EnvironmentError
|
|
|
|
|
2014-04-14 19:18:16 -04:00
|
|
|
syn keyword pythonExClass AssertionError AttributeError EOFError
|
2013-09-12 10:23:36 -04:00
|
|
|
syn keyword pythonExClass FloatingPointError GeneratorExit IOError
|
|
|
|
syn keyword pythonExClass ImportError IndexError KeyError
|
|
|
|
syn keyword pythonExClass KeyboardInterrupt MemoryError NameError
|
|
|
|
syn keyword pythonExClass NotImplementedError OSError OverflowError
|
|
|
|
syn keyword pythonExClass ReferenceError RuntimeError StopIteration
|
|
|
|
syn keyword pythonExClass SyntaxError IndentationError TabError
|
|
|
|
syn keyword pythonExClass SystemError SystemExit TypeError
|
|
|
|
syn keyword pythonExClass UnboundLocalError UnicodeError
|
|
|
|
syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError
|
2014-04-14 19:18:16 -04:00
|
|
|
syn keyword pythonExClass UnicodeTranslateError ValueError
|
2013-09-12 10:23:36 -04:00
|
|
|
syn keyword pythonExClass WindowsError ZeroDivisionError
|
|
|
|
|
2014-04-14 19:18:16 -04:00
|
|
|
syn keyword pythonExClass Warning UserWarning DeprecationWarning
|
2013-09-12 10:23:36 -04:00
|
|
|
syn keyword pythonExClass PendingDepricationWarning SyntaxWarning
|
2014-04-14 19:18:16 -04:00
|
|
|
syn keyword pythonExClass RuntimeWarning FutureWarning OverflowWarning
|
2013-09-12 10:23:36 -04:00
|
|
|
syn keyword pythonExClass ImportWarning UnicodeWarning
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists("python_slow_sync") && python_slow_sync != 0
|
|
|
|
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
|
|
|
|
endif
|
|
|
|
|
|
|
|
if version >= 508 || !exists("did_python_syn_inits")
|
|
|
|
if version <= 508
|
|
|
|
let did_python_syn_inits = 1
|
|
|
|
command -nargs=+ HiLink hi link <args>
|
|
|
|
else
|
|
|
|
command -nargs=+ HiLink hi def link <args>
|
|
|
|
endif
|
|
|
|
|
|
|
|
HiLink pythonStatement Statement
|
2014-04-14 19:18:16 -04:00
|
|
|
HiLink pythonImport Statement
|
2013-09-12 10:23:36 -04:00
|
|
|
HiLink pythonFunction Function
|
|
|
|
HiLink pythonConditional Conditional
|
|
|
|
HiLink pythonRepeat Repeat
|
|
|
|
HiLink pythonException Exception
|
|
|
|
HiLink pythonOperator Operator
|
|
|
|
|
|
|
|
HiLink pythonDecorator Define
|
|
|
|
|
|
|
|
HiLink pythonComment Comment
|
|
|
|
HiLink pythonCoding Special
|
|
|
|
HiLink pythonRun Special
|
|
|
|
HiLink pythonTodo Todo
|
|
|
|
|
|
|
|
HiLink pythonError Error
|
|
|
|
HiLink pythonIndentError Error
|
|
|
|
HiLink pythonSpaceError Error
|
|
|
|
|
|
|
|
HiLink pythonString String
|
2014-04-14 19:18:16 -04:00
|
|
|
HiLink pythonBString String
|
2013-09-12 10:23:36 -04:00
|
|
|
HiLink pythonUniString String
|
|
|
|
HiLink pythonRawString String
|
|
|
|
HiLink pythonUniRawString String
|
|
|
|
|
|
|
|
HiLink pythonEscape Special
|
2014-04-14 19:18:16 -04:00
|
|
|
HiLink pythonBEscape Special
|
2013-09-12 10:23:36 -04:00
|
|
|
HiLink pythonEscapeError Error
|
2014-04-14 19:18:16 -04:00
|
|
|
HiLink pythonBEscapeError Error
|
2013-09-12 10:23:36 -04:00
|
|
|
HiLink pythonUniEscape Special
|
|
|
|
HiLink pythonUniEscapeError Error
|
|
|
|
HiLink pythonUniRawEscape Special
|
|
|
|
HiLink pythonUniRawEscapeError Error
|
|
|
|
|
2014-04-14 19:18:16 -04:00
|
|
|
HiLink pythonStrFormat Special
|
2013-09-12 10:23:36 -04:00
|
|
|
|
|
|
|
HiLink pythonDocTest Special
|
|
|
|
HiLink pythonDocTest2 Special
|
|
|
|
|
|
|
|
HiLink pythonNumber Number
|
|
|
|
HiLink pythonHexNumber Number
|
|
|
|
HiLink pythonFloat Float
|
2014-04-14 19:18:16 -04:00
|
|
|
HiLink pythonOctalError Error
|
2013-09-12 10:23:36 -04:00
|
|
|
HiLink pythonHexError Error
|
|
|
|
|
|
|
|
HiLink pythonBuiltinObj Structure
|
|
|
|
HiLink pythonBuiltinFunc Function
|
|
|
|
|
|
|
|
HiLink pythonExClass Structure
|
|
|
|
|
|
|
|
delcommand HiLink
|
|
|
|
endif
|
|
|
|
|
|
|
|
let b:current_syntax = "python"
|
2015-07-18 17:05:45 -04:00
|
|
|
|
|
|
|
endif
|