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