python.vim 25KB

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