python.vim 24KB

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