python3.0.vim 14KB

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