python3.0.vim 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. " Vim syntax file
  2. " Language: Python
  3. " Maintainer: Dmitry Vasiliev <dima@hlabs.spb.ru>
  4. " URL: http://www.hlabs.spb.ru/vim/python3.0.vim
  5. " Last Change: 2010-11-11
  6. " Filenames: *.py
  7. " Version: 3.0.5
  8. "
  9. " Based on python.vim (from Vim 6.1 distribution)
  10. " by Neil Schemenauer <nas@python.ca>
  11. "
  12. " Thanks:
  13. "
  14. " Jeroen Ruigrok van der Werven
  15. " for the idea to highlight erroneous operators
  16. " Pedro Algarvio
  17. " for the patch to enable spell checking only for the right spots
  18. " (strings and comments)
  19. " John Eikenberry
  20. " for the patch fixing small typo
  21. " Caleb Adamantine
  22. " for the patch fixing highlighting for decorators
  23. " Andrea Riciputi
  24. " for the patch with new configuration options
  25. " Anton Butanaev
  26. " for the patch fixing bytes literals highlighting
  27. "
  28. " Options:
  29. "
  30. " For set option do: let OPTION_NAME = 1
  31. " For clear option do: let OPTION_NAME = 0
  32. "
  33. " Option names:
  34. "
  35. " For highlight builtin functions:
  36. " python_highlight_builtins
  37. "
  38. " For highlight builtin objects:
  39. " python_highlight_builtin_objs
  40. "
  41. " For highlight builtin funtions:
  42. " python_highlight_builtin_funcs
  43. "
  44. " For highlight standard exceptions:
  45. " python_highlight_exceptions
  46. "
  47. " For highlight string formatting:
  48. " python_highlight_string_formatting
  49. "
  50. " For highlight str.format syntax:
  51. " python_highlight_string_format
  52. "
  53. " For highlight string.Template syntax:
  54. " python_highlight_string_templates
  55. "
  56. " For highlight indentation errors:
  57. " python_highlight_indent_errors
  58. "
  59. " For highlight trailing spaces:
  60. " python_highlight_space_errors
  61. "
  62. " For highlight doc-tests:
  63. " python_highlight_doctests
  64. "
  65. " If you want all Python highlightings above:
  66. " python_highlight_all
  67. " (This option not override previously set options)
  68. "
  69. " For fast machines:
  70. " python_slow_sync
  71. " For version 5.x: Clear all syntax items
  72. " For version 6.x: Quit when a syntax file was already loaded
  73. if version < 600
  74. syntax clear
  75. elseif exists("b:current_syntax")
  76. finish
  77. endif
  78. if exists("python_highlight_all") && python_highlight_all != 0
  79. " Not override previously set options
  80. if !exists("python_highlight_builtins")
  81. if !exists("python_highlight_builtin_objs")
  82. let python_highlight_builtin_objs = 1
  83. endif
  84. if !exists("python_highlight_builtin_funcs")
  85. let python_highlight_builtin_funcs = 1
  86. endif
  87. endif
  88. if !exists("python_highlight_exceptions")
  89. let python_highlight_exceptions = 1
  90. endif
  91. if !exists("python_highlight_string_formatting")
  92. let python_highlight_string_formatting = 1
  93. endif
  94. if !exists("python_highlight_string_format")
  95. let python_highlight_string_format = 1
  96. endif
  97. if !exists("python_highlight_string_templates")
  98. let python_highlight_string_templates = 1
  99. endif
  100. if !exists("python_highlight_indent_errors")
  101. let python_highlight_indent_errors = 1
  102. endif
  103. if !exists("python_highlight_space_errors")
  104. let python_highlight_space_errors = 1
  105. endif
  106. if !exists("python_highlight_doctests")
  107. let python_highlight_doctests = 1
  108. endif
  109. endif
  110. " Keywords
  111. syn keyword pythonStatement break continue del
  112. syn keyword pythonStatement exec return as
  113. syn keyword pythonStatement pass raise
  114. syn keyword pythonStatement global assert
  115. syn keyword pythonStatement lambda yield
  116. syn keyword pythonStatement with nonlocal
  117. syn keyword pythonStatement False None True
  118. syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
  119. syn match pythonFunction "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
  120. syn keyword pythonRepeat for while
  121. syn keyword pythonConditional if elif else
  122. syn keyword pythonPreCondit import from
  123. syn keyword pythonException try except finally
  124. syn keyword pythonOperator and in is not or
  125. " Decorators (new in Python 2.4)
  126. syn match pythonDecorator "@" display nextgroup=pythonDottedName skipwhite
  127. syn match pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained
  128. syn match pythonDot "\." display containedin=pythonDottedName
  129. " Comments
  130. syn match pythonComment "#.*$" display contains=pythonTodo,@Spell
  131. syn match pythonRun "\%^#!.*$"
  132. syn match pythonCoding "\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
  133. syn keyword pythonTodo TODO FIXME XXX contained
  134. " Errors
  135. syn match pythonError "\<\d\+\D\+\>" display
  136. syn match pythonError "[$?]" display
  137. syn match pythonError "[&|]\{2,}" display
  138. syn match pythonError "[=]\{3,}" display
  139. " TODO: Mixing spaces and tabs also may be used for pretty formatting multiline
  140. " statements. For now I don't know how to work around this.
  141. if exists("python_highlight_indent_errors") && python_highlight_indent_errors != 0
  142. syn match pythonIndentError "^\s*\%( \t\|\t \)\s*\S"me=e-1 display
  143. endif
  144. " Trailing space errors
  145. if exists("python_highlight_space_errors") && python_highlight_space_errors != 0
  146. syn match pythonSpaceError "\s\+$" display
  147. endif
  148. " Strings
  149. syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
  150. syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
  151. syn region pythonString start=+"""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell
  152. syn region pythonString start=+'''+ end=+'''+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceError,@Spell
  153. syn match pythonEscape +\\[abfnrtv'"\\]+ display contained
  154. syn match pythonEscape "\\\o\o\=\o\=" display contained
  155. syn match pythonEscapeError "\\\o\{,2}[89]" display contained
  156. syn match pythonEscape "\\x\x\{2}" display contained
  157. syn match pythonEscapeError "\\x\x\=\X" display contained
  158. syn match pythonEscape "\\$"
  159. syn match pythonEscape "\\u\x\{4}" display contained
  160. syn match pythonEscapeError "\\u\x\{,3}\X" display contained
  161. syn match pythonEscape "\\U\x\{8}" display contained
  162. syn match pythonEscapeError "\\U\x\{,7}\X" display contained
  163. syn match pythonEscape "\\N{[A-Z ]\+}" display contained
  164. syn match pythonEscapeError "\\N{[^A-Z ]\+}" display contained
  165. " Raw strings
  166. syn region pythonRawString start=+[bB]\=[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
  167. syn region pythonRawString start=+[bB]\=[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
  168. syn region pythonRawString start=+[bB]\=[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
  169. syn region pythonRawString start=+[bB]\=[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
  170. syn match pythonRawEscape +\\['"]+ display transparent contained
  171. " Bytes
  172. syn region pythonBytes start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
  173. syn region pythonBytes start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
  174. syn region pythonBytes start=+[bB]"""+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell
  175. syn region pythonBytes start=+[bB]'''+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell
  176. syn match pythonBytesError ".\+" display contained
  177. syn match pythonBytesContent "[\u0000-\u00ff]\+" display contained contains=pythonBytesEscape,pythonBytesEscapeError
  178. syn match pythonBytesEscape +\\[abfnrtv'"\\]+ display contained
  179. syn match pythonBytesEscape "\\\o\o\=\o\=" display contained
  180. syn match pythonBytesEscapeError "\\\o\{,2}[89]" display contained
  181. syn match pythonBytesEscape "\\x\x\{2}" display contained
  182. syn match pythonBytesEscapeError "\\x\x\=\X" display contained
  183. syn match pythonBytesEscape "\\$"
  184. if exists("python_highlight_string_formatting") && python_highlight_string_formatting != 0
  185. " String formatting
  186. syn match pythonStrFormatting "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
  187. syn match pythonStrFormatting "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
  188. endif
  189. if exists("python_highlight_string_format") && python_highlight_string_format != 0
  190. " str.format syntax
  191. syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString
  192. 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\+\)\=[bcdeEfFgGnoxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString
  193. endif
  194. if exists("python_highlight_string_templates") && python_highlight_string_templates != 0
  195. " String templates
  196. syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonRawString
  197. syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonRawString
  198. syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonRawString
  199. endif
  200. if exists("python_highlight_doctests") && python_highlight_doctests != 0
  201. " DocTests
  202. syn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained
  203. syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained
  204. endif
  205. " Numbers (ints, longs, floats, complex)
  206. syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\x*\>" display
  207. syn match pythonHexNumber "\<0[xX]\x\+\>" display
  208. syn match pythonOctNumber "\<0[oO]\o\+\>" display
  209. syn match pythonBinNumber "\<0[bB][01]\+\>" display
  210. syn match pythonNumberError "\<\d\+\D\>" display
  211. syn match pythonNumberError "\<0\d\+\>" display
  212. syn match pythonNumber "\<\d\>" display
  213. syn match pythonNumber "\<[1-9]\d\+\>" display
  214. syn match pythonNumber "\<\d\+[jJ]\>" display
  215. syn match pythonFloat "\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" display
  216. syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display
  217. syn match pythonFloat "\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=" display
  218. syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*\>" display
  219. syn match pythonBinError "\<0[bB][01]*[2-9]\d*\>" display
  220. if exists("python_highlight_builtin_objs") && python_highlight_builtin_objs != 0
  221. " Builtin objects and types
  222. syn keyword pythonBuiltinObj Ellipsis NotImplemented
  223. syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
  224. endif
  225. if exists("python_highlight_builtin_funcs") && python_highlight_builtin_funcs != 0
  226. " Builtin functions
  227. syn keyword pythonBuiltinFunc __import__ abs all any ascii
  228. syn keyword pythonBuiltinFunc bin bool bytearray bytes
  229. syn keyword pythonBuiltinFunc chr classmethod cmp compile complex
  230. syn keyword pythonBuiltinFunc delattr dict dir divmod enumerate eval
  231. syn keyword pythonBuiltinFunc exec filter float format frozenset getattr
  232. syn keyword pythonBuiltinFunc globals hasattr hash hex id
  233. syn keyword pythonBuiltinFunc input int isinstance
  234. syn keyword pythonBuiltinFunc issubclass iter len list locals map max
  235. syn keyword pythonBuiltinFunc memoryview min next object oct open ord
  236. syn keyword pythonBuiltinFunc pow print property range
  237. syn keyword pythonBuiltinFunc repr reversed round set setattr
  238. syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple
  239. syn keyword pythonBuiltinFunc type vars zip
  240. endif
  241. if exists("python_highlight_exceptions") && python_highlight_exceptions != 0
  242. " Builtin exceptions and warnings
  243. syn keyword pythonExClass BaseException
  244. syn keyword pythonExClass Exception ArithmeticError
  245. syn keyword pythonExClass LookupError EnvironmentError
  246. syn keyword pythonExClass AssertionError AttributeError BufferError EOFError
  247. syn keyword pythonExClass FloatingPointError GeneratorExit IOError
  248. syn keyword pythonExClass ImportError IndexError KeyError
  249. syn keyword pythonExClass KeyboardInterrupt MemoryError NameError
  250. syn keyword pythonExClass NotImplementedError OSError OverflowError
  251. syn keyword pythonExClass ReferenceError RuntimeError StopIteration
  252. syn keyword pythonExClass SyntaxError IndentationError TabError
  253. syn keyword pythonExClass SystemError SystemExit TypeError
  254. syn keyword pythonExClass UnboundLocalError UnicodeError
  255. syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError
  256. syn keyword pythonExClass UnicodeTranslateError ValueError VMSError
  257. syn keyword pythonExClass WindowsError ZeroDivisionError
  258. syn keyword pythonExClass Warning UserWarning BytesWarning DeprecationWarning
  259. syn keyword pythonExClass PendingDepricationWarning SyntaxWarning
  260. syn keyword pythonExClass RuntimeWarning FutureWarning
  261. syn keyword pythonExClass ImportWarning UnicodeWarning
  262. endif
  263. if exists("python_slow_sync") && python_slow_sync != 0
  264. syn sync minlines=2000
  265. else
  266. " This is fast but code inside triple quoted strings screws it up. It
  267. " is impossible to fix because the only way to know if you are inside a
  268. " triple quoted string is to start from the beginning of the file.
  269. syn sync match pythonSync grouphere NONE "):$"
  270. syn sync maxlines=200
  271. endif
  272. if version >= 508 || !exists("did_python_syn_inits")
  273. if version <= 508
  274. let did_python_syn_inits = 1
  275. command -nargs=+ HiLink hi link <args>
  276. else
  277. command -nargs=+ HiLink hi def link <args>
  278. endif
  279. HiLink pythonStatement Statement
  280. HiLink pythonPreCondit Statement
  281. HiLink pythonFunction Function
  282. HiLink pythonConditional Conditional
  283. HiLink pythonRepeat Repeat
  284. HiLink pythonException Exception
  285. HiLink pythonOperator Operator
  286. HiLink pythonDecorator Define
  287. HiLink pythonDottedName Function
  288. HiLink pythonDot Normal
  289. HiLink pythonComment Comment
  290. HiLink pythonCoding Special
  291. HiLink pythonRun Special
  292. HiLink pythonTodo Todo
  293. HiLink pythonError Error
  294. HiLink pythonIndentError Error
  295. HiLink pythonSpaceError Error
  296. HiLink pythonString String
  297. HiLink pythonRawString String
  298. HiLink pythonEscape Special
  299. HiLink pythonEscapeError Error
  300. HiLink pythonBytes String
  301. HiLink pythonBytesContent String
  302. HiLink pythonBytesError Error
  303. HiLink pythonBytesEscape Special
  304. HiLink pythonBytesEscapeError Error
  305. HiLink pythonStrFormatting Special
  306. HiLink pythonStrFormat Special
  307. HiLink pythonStrTemplate Special
  308. HiLink pythonDocTest Special
  309. HiLink pythonDocTest2 Special
  310. HiLink pythonNumber Number
  311. HiLink pythonHexNumber Number
  312. HiLink pythonOctNumber Number
  313. HiLink pythonBinNumber Number
  314. HiLink pythonFloat Float
  315. HiLink pythonNumberError Error
  316. HiLink pythonOctError Error
  317. HiLink pythonHexError Error
  318. HiLink pythonBinError Error
  319. HiLink pythonBuiltinObj Structure
  320. HiLink pythonBuiltinFunc Function
  321. HiLink pythonExClass Structure
  322. delcommand HiLink
  323. endif
  324. let b:current_syntax = "python"