PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/usr/share/vim/vim74/syntax/python.vim

https://gitlab.com/kinwei/IFE-task7
Vim Script | 323 lines | 235 code | 14 blank | 74 comment | 13 complexity | 22a841bc697f7119efd01cbaa5f62f40 MD5 | raw file
  1. " Vim syntax file
  2. " Language: Python
  3. " Maintainer: Zvezdan Petkovic <zpetkovic@acm.org>
  4. " Last Change: 2015 Jul 14
  5. " Credits: Neil Schemenauer <nas@python.ca>
  6. " Dmitry Vasiliev
  7. "
  8. " This version is a major rewrite by Zvezdan Petkovic.
  9. "
  10. " - introduced highlighting of doctests
  11. " - updated keywords, built-ins, and exceptions
  12. " - corrected regular expressions for
  13. "
  14. " * functions
  15. " * decorators
  16. " * strings
  17. " * escapes
  18. " * numbers
  19. " * space error
  20. "
  21. " - corrected synchronization
  22. " - more highlighting is ON by default, except
  23. " - space error highlighting is OFF by default
  24. "
  25. " Optional highlighting can be controlled using these variables.
  26. "
  27. " let python_no_builtin_highlight = 1
  28. " let python_no_doctest_code_highlight = 1
  29. " let python_no_doctest_highlight = 1
  30. " let python_no_exception_highlight = 1
  31. " let python_no_number_highlight = 1
  32. " let python_space_error_highlight = 1
  33. "
  34. " All the options above can be switched on together.
  35. "
  36. " let python_highlight_all = 1
  37. "
  38. " For version 5.x: Clear all syntax items.
  39. " For version 6.x: Quit when a syntax file was already loaded.
  40. if version < 600
  41. syntax clear
  42. elseif exists("b:current_syntax")
  43. finish
  44. endif
  45. " We need nocompatible mode in order to continue lines with backslashes.
  46. " Original setting will be restored.
  47. let s:cpo_save = &cpo
  48. set cpo&vim
  49. " Keep Python keywords in alphabetical order inside groups for easy
  50. " comparison with the table in the 'Python Language Reference'
  51. " https://docs.python.org/2/reference/lexical_analysis.html#keywords,
  52. " https://docs.python.org/3/reference/lexical_analysis.html#keywords.
  53. " Groups are in the order presented in NAMING CONVENTIONS in syntax.txt.
  54. " Exceptions come last at the end of each group (class and def below).
  55. "
  56. " Keywords 'with' and 'as' are new in Python 2.6
  57. " (use 'from __future__ import with_statement' in Python 2.5).
  58. "
  59. " Some compromises had to be made to support both Python 3 and 2.
  60. " We include Python 3 features, but when a definition is duplicated,
  61. " the last definition takes precedence.
  62. "
  63. " - 'False', 'None', and 'True' are keywords in Python 3 but they are
  64. " built-ins in 2 and will be highlighted as built-ins below.
  65. " - 'exec' is a built-in in Python 3 and will be highlighted as
  66. " built-in below.
  67. " - 'nonlocal' is a keyword in Python 3 and will be highlighted.
  68. " - 'print' is a built-in in Python 3 and will be highlighted as
  69. " built-in below (use 'from __future__ import print_function' in 2)
  70. "
  71. syn keyword pythonStatement False, None, True
  72. syn keyword pythonStatement as assert break continue del exec global
  73. syn keyword pythonStatement lambda nonlocal pass print return with yield
  74. syn keyword pythonStatement class def nextgroup=pythonFunction skipwhite
  75. syn keyword pythonConditional elif else if
  76. syn keyword pythonRepeat for while
  77. syn keyword pythonOperator and in is not or
  78. syn keyword pythonException except finally raise try
  79. syn keyword pythonInclude from import
  80. " Decorators (new in Python 2.4)
  81. syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite
  82. " The zero-length non-grouping match before the function name is
  83. " extremely important in pythonFunction. Without it, everything is
  84. " interpreted as a function inside the contained environment of
  85. " doctests.
  86. " A dot must be allowed because of @MyClass.myfunc decorators.
  87. syn match pythonFunction
  88. \ "\%(\%(def\s\|class\s\|@\)\s*\)\@<=\h\%(\w\|\.\)*" contained
  89. syn match pythonComment "#.*$" contains=pythonTodo,@Spell
  90. syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained
  91. " Triple-quoted strings can contain doctests.
  92. syn region pythonString matchgroup=pythonQuotes
  93. \ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
  94. \ contains=pythonEscape,@Spell
  95. syn region pythonString matchgroup=pythonTripleQuotes
  96. \ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
  97. \ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
  98. syn region pythonRawString matchgroup=pythonQuotes
  99. \ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
  100. \ contains=@Spell
  101. syn region pythonRawString matchgroup=pythonTripleQuotes
  102. \ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
  103. \ contains=pythonSpaceError,pythonDoctest,@Spell
  104. syn match pythonEscape +\\[abfnrtv'"\\]+ contained
  105. syn match pythonEscape "\\\o\{1,3}" contained
  106. syn match pythonEscape "\\x\x\{2}" contained
  107. syn match pythonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained
  108. " Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/
  109. syn match pythonEscape "\\N{\a\+\%(\s\a\+\)*}" contained
  110. syn match pythonEscape "\\$"
  111. if exists("python_highlight_all")
  112. if exists("python_no_builtin_highlight")
  113. unlet python_no_builtin_highlight
  114. endif
  115. if exists("python_no_doctest_code_highlight")
  116. unlet python_no_doctest_code_highlight
  117. endif
  118. if exists("python_no_doctest_highlight")
  119. unlet python_no_doctest_highlight
  120. endif
  121. if exists("python_no_exception_highlight")
  122. unlet python_no_exception_highlight
  123. endif
  124. if exists("python_no_number_highlight")
  125. unlet python_no_number_highlight
  126. endif
  127. let python_space_error_highlight = 1
  128. endif
  129. " It is very important to understand all details before changing the
  130. " regular expressions below or their order.
  131. " The word boundaries are *not* the floating-point number boundaries
  132. " because of a possible leading or trailing decimal point.
  133. " The expressions below ensure that all valid number literals are
  134. " highlighted, and invalid number literals are not. For example,
  135. "
  136. " - a decimal point in '4.' at the end of a line is highlighted,
  137. " - a second dot in 1.0.0 is not highlighted,
  138. " - 08 is not highlighted,
  139. " - 08e0 or 08j are highlighted,
  140. "
  141. " and so on, as specified in the 'Python Language Reference'.
  142. " https://docs.python.org/2/reference/lexical_analysis.html#numeric-literals
  143. " https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals
  144. if !exists("python_no_number_highlight")
  145. " numbers (including longs and complex)
  146. syn match pythonNumber "\<0[oO]\=\o\+[Ll]\=\>"
  147. syn match pythonNumber "\<0[xX]\x\+[Ll]\=\>"
  148. syn match pythonNumber "\<0[bB][01]\+[Ll]\=\>"
  149. syn match pythonNumber "\<\%([1-9]\d*\|0\)[Ll]\=\>"
  150. syn match pythonNumber "\<\d\+[jJ]\>"
  151. syn match pythonNumber "\<\d\+[eE][+-]\=\d\+[jJ]\=\>"
  152. syn match pythonNumber
  153. \ "\<\d\+\.\%([eE][+-]\=\d\+\)\=[jJ]\=\%(\W\|$\)\@="
  154. syn match pythonNumber
  155. \ "\%(^\|\W\)\zs\d*\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>"
  156. endif
  157. " Group the built-ins in the order in the 'Python Library Reference' for
  158. " easier comparison.
  159. " https://docs.python.org/2/library/constants.html
  160. " https://docs.python.org/3/library/constants.html
  161. " http://docs.python.org/2/library/functions.html
  162. " http://docs.python.org/3/library/functions.html
  163. " http://docs.python.org/2/library/functions.html#non-essential-built-in-functions
  164. " http://docs.python.org/3/library/functions.html#non-essential-built-in-functions
  165. " Python built-in functions are in alphabetical order.
  166. if !exists("python_no_builtin_highlight")
  167. " built-in constants
  168. " 'False', 'True', and 'None' are also reserved words in Python 3
  169. syn keyword pythonBuiltin False True None
  170. syn keyword pythonBuiltin NotImplemented Ellipsis __debug__
  171. " built-in functions
  172. syn keyword pythonBuiltin abs all any bin bool bytearray callable chr
  173. syn keyword pythonBuiltin classmethod compile complex delattr dict dir
  174. syn keyword pythonBuiltin divmod enumerate eval filter float format
  175. syn keyword pythonBuiltin frozenset getattr globals hasattr hash
  176. syn keyword pythonBuiltin help hex id input int isinstance
  177. syn keyword pythonBuiltin issubclass iter len list locals map max
  178. syn keyword pythonBuiltin memoryview min next object oct open ord pow
  179. syn keyword pythonBuiltin print property range repr reversed round set
  180. syn keyword pythonBuiltin setattr slice sorted staticmethod str
  181. syn keyword pythonBuiltin sum super tuple type vars zip __import__
  182. " Python 2 only
  183. syn keyword pythonBuiltin basestring cmp execfile file
  184. syn keyword pythonBuiltin long raw_input reduce reload unichr
  185. syn keyword pythonBuiltin unicode xrange
  186. " Python 3 only
  187. syn keyword pythonBuiltin ascii bytes exec
  188. " non-essential built-in functions; Python 2 only
  189. syn keyword pythonBuiltin apply buffer coerce intern
  190. endif
  191. " From the 'Python Library Reference' class hierarchy at the bottom.
  192. " http://docs.python.org/2/library/exceptions.html
  193. " http://docs.python.org/3/library/exceptions.html
  194. if !exists("python_no_exception_highlight")
  195. " builtin base exceptions (used mostly as base classes for other exceptions)
  196. syn keyword pythonExceptions BaseException Exception
  197. syn keyword pythonExceptions ArithmeticError BufferError
  198. syn keyword pythonExceptions LookupError
  199. " builtin base exceptions removed in Python 3
  200. syn keyword pythonExceptions EnvironmentError StandardError
  201. " builtin exceptions (actually raised)
  202. syn keyword pythonExceptions AssertionError AttributeError
  203. syn keyword pythonExceptions EOFError FloatingPointError GeneratorExit
  204. syn keyword pythonExceptions ImportError IndentationError
  205. syn keyword pythonExceptions IndexError KeyError KeyboardInterrupt
  206. syn keyword pythonExceptions MemoryError NameError NotImplementedError
  207. syn keyword pythonExceptions OSError OverflowError ReferenceError
  208. syn keyword pythonExceptions RuntimeError StopIteration SyntaxError
  209. syn keyword pythonExceptions SystemError SystemExit TabError TypeError
  210. syn keyword pythonExceptions UnboundLocalError UnicodeError
  211. syn keyword pythonExceptions UnicodeDecodeError UnicodeEncodeError
  212. syn keyword pythonExceptions UnicodeTranslateError ValueError
  213. syn keyword pythonExceptions ZeroDivisionError
  214. " builtin OS exceptions in Python 3
  215. syn keyword pythonExceptions BlockingIOError BrokenPipeError
  216. syn keyword pythonExceptions ChildProcessError ConnectionAbortedError
  217. syn keyword pythonExceptions ConnectionError ConnectionRefusedError
  218. syn keyword pythonExceptions ConnectionResetError FileExistsError
  219. syn keyword pythonExceptions FileNotFoundError InterruptedError
  220. syn keyword pythonExceptions IsADirectoryError NotADirectoryError
  221. syn keyword pythonExceptions PermissionError ProcessLookupError
  222. syn keyword pythonExceptions TimeoutError
  223. " builtin exceptions deprecated/removed in Python 3
  224. syn keyword pythonExceptions IOError VMSError WindowsError
  225. " builtin warnings
  226. syn keyword pythonExceptions BytesWarning DeprecationWarning FutureWarning
  227. syn keyword pythonExceptions ImportWarning PendingDeprecationWarning
  228. syn keyword pythonExceptions RuntimeWarning SyntaxWarning UnicodeWarning
  229. syn keyword pythonExceptions UserWarning Warning
  230. " builtin warnings in Python 3
  231. syn keyword pythonExceptions ResourceWarning
  232. endif
  233. if exists("python_space_error_highlight")
  234. " trailing whitespace
  235. syn match pythonSpaceError display excludenl "\s\+$"
  236. " mixed tabs and spaces
  237. syn match pythonSpaceError display " \+\t"
  238. syn match pythonSpaceError display "\t\+ "
  239. endif
  240. " Do not spell doctests inside strings.
  241. " Notice that the end of a string, either ''', or """, will end the contained
  242. " doctest too. Thus, we do *not* need to have it as an end pattern.
  243. if !exists("python_no_doctest_highlight")
  244. if !exists("python_no_doctest_code_highlight")
  245. syn region pythonDoctest
  246. \ start="^\s*>>>\s" end="^\s*$"
  247. \ contained contains=ALLBUT,pythonDoctest,@Spell
  248. syn region pythonDoctestValue
  249. \ start=+^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$"
  250. \ contained
  251. else
  252. syn region pythonDoctest
  253. \ start="^\s*>>>" end="^\s*$"
  254. \ contained contains=@NoSpell
  255. endif
  256. endif
  257. " Sync at the beginning of class, function, or method definition.
  258. syn sync match pythonSync grouphere NONE "^\s*\%(def\|class\)\s\+\h\w*\s*("
  259. if version >= 508 || !exists("did_python_syn_inits")
  260. if version <= 508
  261. let did_python_syn_inits = 1
  262. command -nargs=+ HiLink hi link <args>
  263. else
  264. command -nargs=+ HiLink hi def link <args>
  265. endif
  266. " The default highlight links. Can be overridden later.
  267. HiLink pythonStatement Statement
  268. HiLink pythonConditional Conditional
  269. HiLink pythonRepeat Repeat
  270. HiLink pythonOperator Operator
  271. HiLink pythonException Exception
  272. HiLink pythonInclude Include
  273. HiLink pythonDecorator Define
  274. HiLink pythonFunction Function
  275. HiLink pythonComment Comment
  276. HiLink pythonTodo Todo
  277. HiLink pythonString String
  278. HiLink pythonRawString String
  279. HiLink pythonQuotes String
  280. HiLink pythonTripleQuotes pythonQuotes
  281. HiLink pythonEscape Special
  282. if !exists("python_no_number_highlight")
  283. HiLink pythonNumber Number
  284. endif
  285. if !exists("python_no_builtin_highlight")
  286. HiLink pythonBuiltin Function
  287. endif
  288. if !exists("python_no_exception_highlight")
  289. HiLink pythonExceptions Structure
  290. endif
  291. if exists("python_space_error_highlight")
  292. HiLink pythonSpaceError Error
  293. endif
  294. if !exists("python_no_doctest_highlight")
  295. HiLink pythonDoctest Special
  296. HiLink pythonDoctestValue Define
  297. endif
  298. delcommand HiLink
  299. endif
  300. let b:current_syntax = "python"
  301. let &cpo = s:cpo_save
  302. unlet s:cpo_save
  303. " vim:set sw=2 sts=2 ts=8 noet: