python.vim 24KB

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