forked from hdima/python-syntax
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.vim
More file actions
242 lines (199 loc) · 13.6 KB
/
Copy pathpython.vim
File metadata and controls
242 lines (199 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
if exists("b:current_syntax")
finish
endif
syn keyword pythonInstanceVariable self
syn keyword pythonClassVaraible cls
syn keyword pythonStatement break continue del
syn keyword pythonStatement exec return
syn keyword pythonStatement pass yield
syn keyword pythonStatement raise nextgroup=pythonIdentifier,pythonExClass skipwhite
syn keyword pythonStatement global assert
syn keyword pythonStatement lambda
syn keyword pythonStatement with
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
syn keyword pythonRepeat for while
syn keyword pythonConditional if elif else
" The standard pyrex.vim unconditionally removes the pythonInclude group, so
" we provide a dummy group here to avoid crashing pyrex.vim.
syn keyword pythonException try except finally
syn keyword pythonOperator and in is not or
syn match pythonStatement "\s*\([.,]\)\@<!\<yield\>"
syn keyword pythonInclude import
syn keyword pythonImport import
syn match pythonIdentifier "\v[a-zA-Z_][a-zA-Z0-9_]*"
syn match pythonRaiseFromStatement "from\>"
syn match pythonImport "^\s*\zsfrom\>"
syn keyword pythonStatement as nonlocal
syn match pythonStatement "\v(\.)@<!<await>"
syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained
syn match pythonStatement "\<async\s\+def\>" nextgroup=pythonFunction skipwhite
syn match pythonStatement "\<async\s\+with\>"
syn match pythonStatement "\<async\s\+for\>"
syn match pythonDecorator "@" display nextgroup=pythonDottedName skipwhite
syn match pythonDottedName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*" display contained nextgroup=FunctionParameters
syn match pythonDot "\." display containedin=pythonDottedName
syn match pythonComment "#.*$" display contains=pythonTodo,@Spell
syn match pythonRun "\%^#!.*$"
syn match pythonCoding "\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
syn keyword pythonTodo TODO FIXME XXX contained
syn match pythonError "\<\d\+\D\+\>" display
syn match pythonError "[$?]" display
syn match pythonError "[&|]\{2,}" display
syn match pythonError "[=]\{3,}" display
syn match pythonIndentError "^\s*\%( \t\|\t \)\s*\S"me=e-1 display
syn match pythonSpaceError "\s\+$" display
syn region pythonBytes start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
syn region pythonBytes start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
syn region pythonBytes start=+[bB]"""+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell
syn region pythonBytes start=+[bB]'''+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell
syn match pythonBytesError ".\+" display contained
syn match pythonBytesContent "[\u0000-\u00ff]\+" display contained contains=pythonBytesEscape,pythonBytesEscapeError
syn match pythonBytesEscape +\\[abfnrtv'"\\]+ display contained
syn match pythonBytesEscape "\\\o\o\=\o\=" display contained
syn match pythonBytesEscapeError "\\\o\{,2}[89]" display contained
syn match pythonBytesEscape "\\x\x\{2}" display contained
syn match pythonBytesEscapeError "\\x\x\=\X" display contained
syn match pythonBytesEscape "\\$"
syn match pythonUniEscape "\\u\x\{4}" display contained
syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained
syn match pythonUniEscape "\\U\x\{8}" display contained
syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained
syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained
syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained
syn region pythonSingleQuoteString start=+'+ skip=+\\'+ excludenl end=+'+ end=+$+ keepend contains=pythonEol
syn region pythonDoubleQuoteString start=+"+ skip=+\\"+ excludenl end=+"+ end=+$+ keepend contains=pythonEol
syn region pythonSingleQuoteFString start=+fr\?'+ skip=+\\'+ excludenl end=+'+ end=+$+ keepend contains=pythonEol,pythonSingleQuoteFStringFormat
syn region pythonDoubleQuoteFString start=+fr\?"+ skip=+\\"+ excludenl end=+"+ end=+$+ keepend contains=pythonEol,pythonDoubleQuoteFStringFormat
syn region pythonTripleSingleQuoteString start=+'''+ skip=+\\'+ excludenl end=+'''+ keepend contains=pythonEol
syn region pythonTripleDoubleQuoteString start=+"""+ skip=+\\"+ excludenl end=+"""+ keepend contains=pythonEol
syn region pythonTripleSingleQuoteFString start=+f'''+ skip=+\\'+ excludenl end=+'''+ contains=pythonEol,pythonSingleQuoteFStringFormat
syn region pythonTripleDoubleQuoteFString start=+f"""+ skip=+\\"+ excludenl end=+"""+ contains=pythonEol,pythonDoubleQuoteFStringFormat
syn match pythonEol "\\n" display contained
syn region pythonSingleQuoteFStringFormat matchgroup=Special start=+{+ end=+}+ contains=pythonStatement,pythonConditional,pythonBoolean,pythonDoubleQuoteString,pythonRepeat,pythonNumber,pythonFloat,pythonOperator,pythonInstanceVariable,pythonClassVaraible contained containedin=pythonSingleQuoteFString
syn region pythonDoubleQuoteFStringFormat matchgroup=Special start=+{+ end=+}+ contains=pythonStatement,pythonConditional,pythonBoolean,pythonSingleQuoteString,pythonRepeat,pythonNumber,pythonFloat,pythonOperator,pythonInstanceVariable,pythonClassVaraible contained containedin=pythonDoubleQuoteFString
syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\x*\>" display
syn match pythonOctError "\<0[oO]\=\o*\D\+\d*\>" display
syn match pythonBinError "\<0[bB][01]*\D\+\d*\>" display
syn match pythonHexNumber "\<0[xX]\x\+\>" display
syn match pythonOctNumber "\<0[oO]\o\+\>" display
syn match pythonBinNumber "\<0[bB][01]\+\>" display
syn match pythonNumberError "\<\d\+\D\>" display
syn match pythonNumberError "\<0\d\+\>" display
syn match pythonNumber "\<\d\>" display
syn match pythonNumber "\<[1-9]\d\+\>" display
syn match pythonNumber "\<\d\+[jJ]\>" display
syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*\>" display
syn match pythonBinError "\<0[bB][01]*[2-9]\d*\>" display
syn match pythonFloat "\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" display
syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display
syn match pythonFloat "\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=" display
syn keyword pythonNone None
syn keyword pythonBoolean True False
syn keyword pythonBuiltinObj Ellipsis NotImplemented
syn match pythonBuiltinObj '\v(\.)@<!<(object|bool|int|float|tuple|str|list|dict|set|frozenset|bytearray|bytes)>'
syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__
"
" Builtin functions
"
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(ascii|exec|memoryview|print)>\ze\(' nextgroup=FunctionParameters
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(__import__|abs|all|any)>\ze\(' nextgroup=FunctionParameters
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(bin|chr|classmethod|cmp|compile|complex)>\ze\(' nextgroup=FunctionParameters
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(delattr|dir|divmod|enumerate|eval)>\ze\(' nextgroup=FunctionParameters
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(filter|format|getattr|callable)>\ze\(' nextgroup=FunctionParameters
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(globals|hasattr|hash|hex|id)>\ze\(' nextgroup=FunctionParameters
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(input|isinstance)>\ze\(' nextgroup=FunctionParameters
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(issubclass|iter|len|locals|map|max)>\ze\(' nextgroup=FunctionParameters
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(min|next|oct|open|ord)>\ze\(' nextgroup=FunctionParameters
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(pow|property|range)>\ze\(' nextgroup=FunctionParameters
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(repr|reversed|round|setattr)>\ze\(' nextgroup=FunctionParameters
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(slice|sorted|staticmethod|sum|super)>\ze\(' nextgroup=FunctionParameters
syn match pythonBuiltinFunc '\v(\.)@<!\zs<(type|vars|zip)>\ze\(' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(BlockingIOError|ChildProcessError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(ConnectionError|BrokenPipeError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(ConnectionAbortedError|ConnectionRefusedError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(ConnectionResetError|FileExistsError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(FileNotFoundError|InterruptedError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(IsADirectoryError|NotADirectoryError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(PermissionError|ProcessLookupError TimeoutError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(StopAsyncIteration|ResourceWarning)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!<(BaseException|Exception|ArithmeticError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(LookupError|EnvironmentError|AssertionError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(AttributeError|BufferError|EOFError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(FloatingPointError|GeneratorExit|IOError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(ImportError|IndexError|KeyError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(KeyboardInterrupt|MemoryError|NameError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(NotImplementedError|OSError|OverflowError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(ReferenceError|RuntimeError|StopIteration)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(SyntaxError|IndentationError|TabError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(SystemError|SystemExit|TypeError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(UnboundLocalError|UnicodeError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(UnicodeEncodeError|UnicodeDecodeError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(UnicodeTranslateError|ValueError|VMSError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(WindowsError|ZeroDivisionError)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(Warning|UserWarning|BytesWarning|DeprecationWarning)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(PendingDepricationWarning|SyntaxWarning)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(RuntimeWarning|FutureWarning)>' nextgroup=FunctionParameters
syn match pythonExClass '\v(\.)@<!\zs<(ImportWarning|UnicodeWarning)>' nextgroup=FunctionParameters
" This is fast but code inside triple quoted strings screws it up. It
" is impossible to fix because the only way to know if you are inside a
" triple quoted string is to start from the beginning of the file.
syn sync match pythonSync grouphere NONE "):$"
syn sync maxlines=200
hi def link pythonStatement Statement
hi def link pythonRaiseFromStatement Statement
hi def link pythonImport Include
hi def link pythonFunction Function
hi def link pythonConditional Conditional
hi def link pythonRepeat Repeat
hi def link pythonException Exception
hi def link pythonOperator Operator
hi def link pythonStarArguments Keyword
hi def link pythonDecorator Define
hi def link pythonDottedName Function
hi def link pythonDot Normal
hi def link pythonComment Comment
hi def link pythonCoding Special
hi def link pythonRun Special
hi def link pythonTodo Todo
hi def link pythonError Error
hi def link pythonIndentError Error
hi def link pythonSpaceError Error
hi def link pythonRawString String
hi def link pythonUniEscape Special
hi def link pythonUniEscapeError Error
hi def link pythonBytes String
hi def link pythonRawBytes String
hi def link pythonBytesContent String
hi def link pythonBytesError Error
hi def link pythonBytesEscape Special
hi def link pythonBytesEscapeError Error
hi def link pythonEol Special
hi def link pythonDocTest Special
hi def link pythonDocTest2 Special
hi def link pythonNumber Number
hi def link pythonHexNumber Number
hi def link pythonOctNumber Number
hi def link pythonBinNumber Number
hi def link pythonFloat Float
hi def link pythonNumberError Error
hi def link pythonOctError Error
hi def link pythonHexError Error
hi def link pythonBinError Error
hi def link pythonBoolean Boolean
hi def link pythonNone Constant
hi def link pythonBuiltinObj Structure
hi def link pythonBuiltinFunc Function
hi def link pythonExClass Structure
hi def link pythonInstanceVariable htmlTagN
hi def link pythonClassVaraible htmlTagN
hi def link OptionalParameters htmlTagN
hi def link pythonSingleQuoteFString String
hi def link pythonDoubleQuoteFString String
hi def link pythonSingleQuoteString String
hi def link pythonDoubleQuoteString String
hi def link pythonTripleSingleQuoteString String
hi def link pythonTripleDoubleQuoteString String
hi def link pythonTripleSingleQuoteFString String
hi def link pythonTripleDoubleQuoteFString String
let b:current_syntax = "python"