python.vim 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. " Vim syntax file
  2. " Language: Python
  3. " Maintainer: Dmitry Vasiliev <dima at hlabs dot org>
  4. " URL: https://github.com/hdima/vim-scripts/blob/master/syntax/python/python.vim
  5. " Last Change: 2013-03-10
  6. " Filenames: *.py
  7. " Version: 3.3.0
  8. "
  9. " Based on python.vim (from Vim 6.1 distribution)
  10. " by Neil Schemenauer <nas at python dot ca>
  11. "
  12. " Bugs and feature requests can be reported through email
  13. " <dima at hlabs dot org>, GitHub at:
  14. "
  15. " https://github.com/hdima/vim-scripts/issues
  16. "
  17. " , or Twitter:
  18. "
  19. " https://twitter.com/hdima
  20. "
  21. " Contributors
  22. " ============
  23. "
  24. " Jeroen Ruigrok van der Werven
  25. " Pedro Algarvio
  26. " John Eikenberry
  27. " Caleb Adamantine
  28. " Andrea Riciputi
  29. " Anton Butanaev
  30. " Marc Weber
  31. "
  32. " Options
  33. " =======
  34. "
  35. " :let OPTION_NAME = 1 Enable option
  36. " :let OPTION_NAME = 0 Disable option
  37. "
  38. "
  39. " Option to select Python version
  40. " -------------------------------
  41. "
  42. " python_version_2 Enable highlighting for Python 2
  43. " (Python 3 highlighting is enabled
  44. " by default). Can also be set as
  45. " a buffer (b:python_version_2)
  46. " variable.
  47. "
  48. " You can also use the following local to buffer commands to switch
  49. " between two highlighting modes:
  50. "
  51. " :Python2Syntax Switch to Python 2 highlighting
  52. " mode
  53. " :Python3Syntax Switch to Python 3 highlighting
  54. " mode
  55. "
  56. " Option names used by the script
  57. " -------------------------------
  58. "
  59. " python_highlight_builtins Highlight builtin functions and
  60. " objects
  61. " python_highlight_builtin_objs Highlight builtin objects only
  62. " python_highlight_builtin_funcs Highlight builtin functions only
  63. " python_highlight_exceptions Highlight standard exceptions
  64. " python_highlight_string_formatting Highlight % string formatting
  65. " python_highlight_string_format Highlight str.format syntax
  66. " python_highlight_string_templates Highlight string.Template syntax
  67. " python_highlight_indent_errors Highlight indentation errors
  68. " python_highlight_space_errors Highlight trailing spaces
  69. " python_highlight_doctests Highlight doc-tests
  70. " python_print_as_function Highlight 'print' statement as
  71. " function for Python 2
  72. "
  73. " python_highlight_all Enable all the options above
  74. " NOTE: This option don't override
  75. " any previously set options
  76. "
  77. " python_slow_sync Can be set to 0 for slow machines
  78. "
  79. " For version 5.x: Clear all syntax items
  80. " For versions greater than 6.x: Quit when a syntax file was already loaded
  81. if version < 600
  82. syntax clear
  83. elseif exists("b:current_syntax")
  84. finish
  85. endif
  86. "
  87. " Commands
  88. "
  89. command! -buffer Python2Syntax let b:python_version_2 = 1 | if exists("g:syntax_on") | syn off | endif | syn enable
  90. command! -buffer Python3Syntax let b:python_version_2 = 0 | if exists("g:syntax_on") | syn off | endif | syn enable
  91. " Enable option if it's not defined
  92. function! s:EnableByDefault(name)
  93. if !exists(a:name)
  94. let {a:name} = 1
  95. endif
  96. endfunction
  97. " Check if option is enabled
  98. function! s:Enabled(name)
  99. return exists(a:name) && {a:name} != 0
  100. endfunction
  101. " Is it Python 2 syntax?
  102. function! s:Python2Syntax()
  103. return s:Enabled("b:python_version_2") || s:Enabled("g:python_version_2")
  104. endfunction
  105. "
  106. " Default options
  107. "
  108. call s:EnableByDefault("g:python_slow_sync")
  109. if s:Enabled("g:python_highlight_all")
  110. call s:EnableByDefault("g:python_highlight_builtins")
  111. if s:Enabled("g:python_highlight_builtins")
  112. call s:EnableByDefault("g:python_highlight_builtin_objs")
  113. call s:EnableByDefault("g:python_highlight_builtin_funcs")
  114. endif
  115. call s:EnableByDefault("g:python_highlight_exceptions")
  116. call s:EnableByDefault("g:python_highlight_string_formatting")
  117. call s:EnableByDefault("g:python_highlight_string_format")
  118. call s:EnableByDefault("g:python_highlight_string_templates")
  119. call s:EnableByDefault("g:python_highlight_indent_errors")
  120. call s:EnableByDefault("g:python_highlight_space_errors")
  121. call s:EnableByDefault("g:python_highlight_doctests")
  122. call s:EnableByDefault("g:python_print_as_function")
  123. endif
  124. "
  125. " Keywords
  126. "
  127. syn keyword pythonStatement break continue del
  128. syn keyword pythonStatement exec return
  129. syn keyword pythonStatement pass raise
  130. syn keyword pythonStatement global assert
  131. syn keyword pythonStatement lambda yield
  132. syn keyword pythonStatement with
  133. syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
  134. syn keyword pythonRepeat for while
  135. syn keyword pythonConditional if elif else
  136. syn keyword pythonPreCondit import from
  137. syn keyword pythonException try except finally
  138. syn keyword pythonOperator and in is not or
  139. if s:Python2Syntax()
  140. if !s:Enabled("g:python_print_as_function")
  141. syn keyword pythonStatement print
  142. endif
  143. syn keyword pythonPreCondit as
  144. syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained
  145. else
  146. syn keyword pythonStatement as nonlocal False None True
  147. syn match pythonFunction "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
  148. endif
  149. "
  150. " Decorators (new in Python 2.4)
  151. "
  152. syn match pythonDecorator "@" display nextgroup=pythonDottedName skipwhite
  153. syn match pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained
  154. syn match pythonDot "\." display containedin=pythonDottedName
  155. "
  156. " Comments
  157. "
  158. syn match pythonComment "#.*$" display contains=pythonTodo,@Spell
  159. syn match pythonRun "\%^#!.*$"
  160. syn match pythonCoding "\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
  161. syn keyword pythonTodo TODO FIXME XXX contained
  162. "
  163. " Errors
  164. "
  165. syn match pythonError "\<\d\+\D\+\>" display
  166. syn match pythonError "[$?]" display
  167. syn match pythonError "[&|]\{2,}" display
  168. syn match pythonError "[=]\{3,}" display
  169. " Mixing spaces and tabs also may be used for pretty formatting multiline
  170. " statements
  171. if s:Enabled("g:python_highlight_indent_errors")
  172. syn match pythonIndentError "^\s*\%( \t\|\t \)\s*\S"me=e-1 display
  173. endif
  174. " Trailing space errors
  175. if s:Enabled("g:python_highlight_space_errors")
  176. syn match pythonSpaceError "\s\+$" display
  177. endif
  178. "
  179. " Strings
  180. "
  181. if s:Python2Syntax()
  182. " Python 2 strings
  183. syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
  184. syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
  185. syn region pythonString start=+[bB]\="""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
  186. syn region pythonString start=+[bB]\='''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
  187. else
  188. " Python 3 byte strings
  189. syn region pythonBytes start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
  190. syn region pythonBytes start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
  191. syn region pythonBytes start=+[bB]"""+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell
  192. syn region pythonBytes start=+[bB]'''+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell
  193. syn match pythonBytesError ".\+" display contained
  194. syn match pythonBytesContent "[\u0000-\u00ff]\+" display contained contains=pythonBytesEscape,pythonBytesEscapeError
  195. endif
  196. syn match pythonBytesEscape +\\[abfnrtv'"\\]+ display contained
  197. syn match pythonBytesEscape "\\\o\o\=\o\=" display contained
  198. syn match pythonBytesEscapeError "\\\o\{,2}[89]" display contained
  199. syn match pythonBytesEscape "\\x\x\{2}" display contained
  200. syn match pythonBytesEscapeError "\\x\x\=\X" display contained
  201. syn match pythonBytesEscape "\\$"
  202. syn match pythonUniEscape "\\u\x\{4}" display contained
  203. syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained
  204. syn match pythonUniEscape "\\U\x\{8}" display contained
  205. syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained
  206. syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained
  207. syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained
  208. if s:Python2Syntax()
  209. " Python 2 Unicode strings
  210. syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
  211. syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
  212. syn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
  213. syn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
  214. else
  215. " Python 3 strings
  216. syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
  217. syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
  218. syn region pythonString start=+"""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
  219. syn region pythonString start=+'''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
  220. endif
  221. if s:Python2Syntax()
  222. " Python 2 Unicode raw strings
  223. syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
  224. syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
  225. syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell
  226. syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell
  227. syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained
  228. syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained
  229. endif
  230. " Python 2/3 raw strings
  231. if s:Python2Syntax()
  232. syn region pythonRawString start=+[bB]\=[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
  233. syn region pythonRawString start=+[bB]\=[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
  234. syn region pythonRawString start=+[bB]\=[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
  235. syn region pythonRawString start=+[bB]\=[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
  236. else
  237. syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
  238. syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
  239. syn region pythonRawString start=+[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
  240. syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
  241. syn region pythonRawBytes start=+[bB][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
  242. syn region pythonRawBytes start=+[bB][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
  243. syn region pythonRawBytes start=+[bB][rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
  244. syn region pythonRawBytes start=+[bB][rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
  245. endif
  246. syn match pythonRawEscape +\\['"]+ display transparent contained
  247. if s:Enabled("g:python_highlight_string_formatting")
  248. " % operator string formatting
  249. if s:Python2Syntax()
  250. syn match pythonStrFormatting "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
  251. syn match pythonStrFormatting "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
  252. else
  253. syn match pythonStrFormatting "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
  254. syn match pythonStrFormatting "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
  255. endif
  256. endif
  257. if s:Enabled("g:python_highlight_string_format")
  258. " str.format syntax
  259. if s:Python2Syntax()
  260. syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
  261. 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
  262. else
  263. syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString
  264. 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
  265. endif
  266. endif
  267. if s:Enabled("g:python_highlight_string_templates")
  268. " string.Template format
  269. if s:Python2Syntax()
  270. syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
  271. syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
  272. syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
  273. else
  274. syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonRawString
  275. syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonRawString
  276. syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonRawString
  277. endif
  278. endif
  279. if s:Enabled("g:python_highlight_doctests")
  280. " DocTests
  281. syn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained
  282. syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained
  283. endif
  284. "
  285. " Numbers (ints, longs, floats, complex)
  286. "
  287. if s:Python2Syntax()
  288. syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\+\x*[lL]\=\>" display
  289. syn match pythonOctError "\<0[oO]\=\o*\D\+\d*[lL]\=\>" display
  290. syn match pythonBinError "\<0[bB][01]*\D\+\d*[lL]\=\>" display
  291. syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" display
  292. syn match pythonOctNumber "\<0[oO]\o\+[lL]\=\>" display
  293. syn match pythonBinNumber "\<0[bB][01]\+[lL]\=\>" display
  294. syn match pythonNumberError "\<\d\+\D[lL]\=\>" display
  295. syn match pythonNumber "\<\d[lL]\=\>" display
  296. syn match pythonNumber "\<[0-9]\d\+[lL]\=\>" display
  297. syn match pythonNumber "\<\d\+[lLjJ]\>" display
  298. syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*[lL]\=\>" display
  299. syn match pythonBinError "\<0[bB][01]*[2-9]\d*[lL]\=\>" display
  300. else
  301. syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\x*\>" display
  302. syn match pythonOctError "\<0[oO]\=\o*\D\+\d*\>" display
  303. syn match pythonBinError "\<0[bB][01]*\D\+\d*\>" display
  304. syn match pythonHexNumber "\<0[xX]\x\+\>" display
  305. syn match pythonOctNumber "\<0[oO]\o\+\>" display
  306. syn match pythonBinNumber "\<0[bB][01]\+\>" display
  307. syn match pythonNumberError "\<\d\+\D\>" display
  308. syn match pythonNumberError "\<0\d\+\>" display
  309. syn match pythonNumber "\<\d\>" display
  310. syn match pythonNumber "\<[1-9]\d\+\>" display
  311. syn match pythonNumber "\<\d\+[jJ]\>" display
  312. syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*\>" display
  313. syn match pythonBinError "\<0[bB][01]*[2-9]\d*\>" display
  314. endif
  315. syn match pythonFloat "\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" display
  316. syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display
  317. syn match pythonFloat "\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=" display
  318. "
  319. " Builtin objects and types
  320. "
  321. if s:Enabled("g:python_highlight_builtin_objs")
  322. if s:Python2Syntax()
  323. syn keyword pythonBuiltinObj True False None
  324. endif
  325. syn keyword pythonBuiltinObj Ellipsis NotImplemented
  326. syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
  327. endif
  328. "
  329. " Builtin functions
  330. "
  331. if s:Enabled("g:python_highlight_builtin_funcs")
  332. if s:Python2Syntax()
  333. syn keyword pythonBuiltinFunc apply basestring buffer callable coerce
  334. syn keyword pythonBuiltinFunc execfile file help intern long raw_input
  335. syn keyword pythonBuiltinFunc reduce reload unichr unicode xrange
  336. if s:Enabled("g:python_print_as_function")
  337. syn keyword pythonBuiltinFunc print
  338. endif
  339. else
  340. syn keyword pythonBuiltinFunc ascii exec memoryview print
  341. endif
  342. syn keyword pythonBuiltinFunc __import__ abs all any
  343. syn keyword pythonBuiltinFunc bin bool bytearray bytes
  344. syn keyword pythonBuiltinFunc chr classmethod cmp compile complex
  345. syn keyword pythonBuiltinFunc delattr dict dir divmod enumerate eval
  346. syn keyword pythonBuiltinFunc filter float format frozenset getattr
  347. syn keyword pythonBuiltinFunc globals hasattr hash hex id
  348. syn keyword pythonBuiltinFunc input int isinstance
  349. syn keyword pythonBuiltinFunc issubclass iter len list locals map max
  350. syn keyword pythonBuiltinFunc min next object oct open ord
  351. syn keyword pythonBuiltinFunc pow property range
  352. syn keyword pythonBuiltinFunc repr reversed round set setattr
  353. syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple
  354. syn keyword pythonBuiltinFunc type vars zip
  355. endif
  356. "
  357. " Builtin exceptions and warnings
  358. "
  359. if s:Enabled("g:python_highlight_exceptions")
  360. if s:Python2Syntax()
  361. syn keyword pythonExClass StandardError
  362. else
  363. syn keyword pythonExClass BlockingIOError ChildProcessError
  364. syn keyword pythonExClass ConnectionError BrokenPipeError
  365. syn keyword pythonExClass ConnectionAbortedError ConnectionRefusedError
  366. syn keyword pythonExClass ConnectionResetError FileExistsError
  367. syn keyword pythonExClass FileNotFoundError InterruptedError
  368. syn keyword pythonExClass IsADirectoryError NotADirectoryError
  369. syn keyword pythonExClass PermissionError ProcessLookupError TimeoutError
  370. syn keyword pythonExClass ResourceWarning
  371. endif
  372. syn keyword pythonExClass BaseException
  373. syn keyword pythonExClass Exception ArithmeticError
  374. syn keyword pythonExClass LookupError EnvironmentError
  375. syn keyword pythonExClass AssertionError AttributeError BufferError EOFError
  376. syn keyword pythonExClass FloatingPointError GeneratorExit IOError
  377. syn keyword pythonExClass ImportError IndexError KeyError
  378. syn keyword pythonExClass KeyboardInterrupt MemoryError NameError
  379. syn keyword pythonExClass NotImplementedError OSError OverflowError
  380. syn keyword pythonExClass ReferenceError RuntimeError StopIteration
  381. syn keyword pythonExClass SyntaxError IndentationError TabError
  382. syn keyword pythonExClass SystemError SystemExit TypeError
  383. syn keyword pythonExClass UnboundLocalError UnicodeError
  384. syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError
  385. syn keyword pythonExClass UnicodeTranslateError ValueError VMSError
  386. syn keyword pythonExClass WindowsError ZeroDivisionError
  387. syn keyword pythonExClass Warning UserWarning BytesWarning DeprecationWarning
  388. syn keyword pythonExClass PendingDepricationWarning SyntaxWarning
  389. syn keyword pythonExClass RuntimeWarning FutureWarning
  390. syn keyword pythonExClass ImportWarning UnicodeWarning
  391. endif
  392. if s:Enabled("g:python_slow_sync")
  393. syn sync minlines=2000
  394. else
  395. " This is fast but code inside triple quoted strings screws it up. It
  396. " is impossible to fix because the only way to know if you are inside a
  397. " triple quoted string is to start from the beginning of the file.
  398. syn sync match pythonSync grouphere NONE "):$"
  399. syn sync maxlines=200
  400. endif
  401. if version >= 508 || !exists("did_python_syn_inits")
  402. if version <= 508
  403. let did_python_syn_inits = 1
  404. command -nargs=+ HiLink hi link <args>
  405. else
  406. command -nargs=+ HiLink hi def link <args>
  407. endif
  408. HiLink pythonStatement Statement
  409. HiLink pythonPreCondit Statement
  410. HiLink pythonFunction Function
  411. HiLink pythonConditional Conditional
  412. HiLink pythonRepeat Repeat
  413. HiLink pythonException Exception
  414. HiLink pythonOperator Operator
  415. HiLink pythonDecorator Define
  416. HiLink pythonDottedName Function
  417. HiLink pythonDot Normal
  418. HiLink pythonComment Comment
  419. HiLink pythonCoding Special
  420. HiLink pythonRun Special
  421. HiLink pythonTodo Todo
  422. HiLink pythonError Error
  423. HiLink pythonIndentError Error
  424. HiLink pythonSpaceError Error
  425. HiLink pythonString String
  426. HiLink pythonRawString String
  427. HiLink pythonUniEscape Special
  428. HiLink pythonUniEscapeError Error
  429. if s:Python2Syntax()
  430. HiLink pythonUniString String
  431. HiLink pythonUniRawString String
  432. HiLink pythonUniRawEscape Special
  433. HiLink pythonUniRawEscapeError Error
  434. else
  435. HiLink pythonBytes String
  436. HiLink pythonRawBytes String
  437. HiLink pythonBytesContent String
  438. HiLink pythonBytesError Error
  439. HiLink pythonBytesEscape Special
  440. HiLink pythonBytesEscapeError Error
  441. endif
  442. HiLink pythonStrFormatting Special
  443. HiLink pythonStrFormat Special
  444. HiLink pythonStrTemplate Special
  445. HiLink pythonDocTest Special
  446. HiLink pythonDocTest2 Special
  447. HiLink pythonNumber Number
  448. HiLink pythonHexNumber Number
  449. HiLink pythonOctNumber Number
  450. HiLink pythonBinNumber Number
  451. HiLink pythonFloat Float
  452. HiLink pythonNumberError Error
  453. HiLink pythonOctError Error
  454. HiLink pythonHexError Error
  455. HiLink pythonBinError Error
  456. HiLink pythonBuiltinObj Structure
  457. HiLink pythonBuiltinFunc Function
  458. HiLink pythonExClass Structure
  459. delcommand HiLink
  460. endif
  461. let b:current_syntax = "python"