python.vim 24KB

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