python.vim 25KB

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