PageRenderTime 24ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/vim/syntax/python.vim

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