Subversion Repositories programming

Rev

Details | Last modification | View Log | RSS feed

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