├── .gitignore ├── LICENSE.txt ├── README.md ├── ftdetect └── cython.vim ├── ftplugin └── cython.vim └── syntax └── cython.vim /.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Gabriel Pettier 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | vim-cython 2 | ========== 3 | 4 | Some utilities for editing Cython files with vim. Install using your favorite 5 | plugin manager. 6 | 7 | Syntax 8 | ------ 9 | 10 | The syntax file is based on https://github.com/anntzer/python-syntax. 11 | 12 | Commands 13 | -------- 14 | 15 | `:make` runs `cython -a` and opens the annotated source in a browser. 16 | -------------------------------------------------------------------------------- /ftdetect/cython.vim: -------------------------------------------------------------------------------- 1 | au BufRead,BufNewFile *.pxd,*.pxi,*.pyx set filetype=cython 2 | -------------------------------------------------------------------------------- /ftplugin/cython.vim: -------------------------------------------------------------------------------- 1 | " Do NOT check for b:did_ftplugin here, as it is set by pyrex.vim. 2 | setlocal commentstring=#\ %s 3 | setlocal makeprg=cython\ -a\ %\ &&\ xdg-open\ '%<.html' 4 | " Don't be fooled by "cdef foo = (...)" when searching for funcname. 5 | nmap gd /\<\(def\\|cdef\\|cpdef\)\>\s[^=]*\<\> 6 | -------------------------------------------------------------------------------- /syntax/cython.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: Cython 3 | " Current Maintainer: Antony Lee 4 | " URL: https://github.com/anntzer/vim-cython 5 | " Last Change: 2016-03-21 6 | " Filenames: *.pyx 7 | " Version: 0.1 8 | " 9 | " Based on python.vim (from Vim 6.1 distribution) 10 | " Dmitry Vasiliev 11 | " 12 | " Options 13 | " ======= 14 | " 15 | " :let OPTION_NAME = 1 Enable option 16 | " :let OPTION_NAME = 0 Disable option 17 | " 18 | " 19 | " Option to select Python version 20 | " ------------------------------- 21 | " 22 | " python_version_2 Enable highlighting for Python 2 23 | " (Python 3 highlighting is enabled 24 | " by default). Can also be set as 25 | " a buffer (b:python_version_2) 26 | " variable. 27 | " 28 | " You can also use the following local to buffer commands to switch 29 | " between two highlighting modes: 30 | " 31 | " :Python2Syntax Switch to Python 2 highlighting 32 | " mode 33 | " :Python3Syntax Switch to Python 3 highlighting 34 | " mode 35 | " 36 | " Option names used by the script 37 | " ------------------------------- 38 | " 39 | " python_highlight_builtins Highlight builtin functions and 40 | " objects 41 | " python_highlight_builtin_objs Highlight builtin objects only 42 | " python_highlight_builtin_funcs Highlight builtin functions only 43 | " python_highlight_exceptions Highlight standard exceptions 44 | " python_highlight_string_formatting Highlight % string formatting 45 | " python_highlight_string_format Highlight str.format syntax 46 | " python_highlight_string_templates Highlight string.Template syntax 47 | " python_highlight_indent_errors Highlight indentation errors 48 | " python_highlight_space_errors Highlight trailing spaces 49 | " python_highlight_doctests Highlight doc-tests 50 | " python_print_as_function Highlight 'print' statement as 51 | " function for Python 2 52 | " python_highlight_file_headers_as_comments 53 | " Highlight shebang and coding 54 | " headers as comments 55 | " 56 | " python_highlight_all Enable all the options above 57 | " NOTE: This option don't override 58 | " any previously set options 59 | " 60 | " python_slow_sync Can be set to 0 for slow machines 61 | " 62 | 63 | " For version 5.x: Clear all syntax items 64 | " For versions greater than 6.x: Quit when a syntax file was already loaded 65 | if version < 600 66 | syntax clear 67 | elseif exists("b:current_syntax") 68 | finish 69 | endif 70 | 71 | " 72 | " Commands 73 | " 74 | command! -buffer Python2Syntax let b:python_version_2 = 1 | let &syntax=&syntax 75 | command! -buffer Python3Syntax let b:python_version_2 = 0 | let &syntax=&syntax 76 | 77 | " Enable option if it's not defined 78 | function! s:EnableByDefault(name) 79 | if !exists(a:name) 80 | let {a:name} = 1 81 | endif 82 | endfunction 83 | 84 | " Check if option is enabled 85 | function! s:Enabled(name) 86 | return exists(a:name) && {a:name} 87 | endfunction 88 | 89 | " Is it Python 2 syntax? 90 | function! s:Python2Syntax() 91 | if exists("b:python_version_2") 92 | return b:python_version_2 93 | endif 94 | return s:Enabled("g:python_version_2") 95 | endfunction 96 | 97 | " 98 | " Default options 99 | " 100 | 101 | call s:EnableByDefault("g:python_slow_sync") 102 | 103 | if s:Enabled("g:python_highlight_all") 104 | call s:EnableByDefault("g:python_highlight_builtins") 105 | if s:Enabled("g:python_highlight_builtins") 106 | call s:EnableByDefault("g:python_highlight_builtin_objs") 107 | call s:EnableByDefault("g:python_highlight_builtin_funcs") 108 | endif 109 | call s:EnableByDefault("g:python_highlight_exceptions") 110 | call s:EnableByDefault("g:python_highlight_string_formatting") 111 | call s:EnableByDefault("g:python_highlight_string_format") 112 | call s:EnableByDefault("g:python_highlight_string_templates") 113 | call s:EnableByDefault("g:python_highlight_indent_errors") 114 | call s:EnableByDefault("g:python_highlight_space_errors") 115 | call s:EnableByDefault("g:python_highlight_doctests") 116 | call s:EnableByDefault("g:python_print_as_function") 117 | endif 118 | 119 | " 120 | " Builtin isolator 121 | " 122 | 123 | syn match pythonBuiltinIsolator "\(\.[\n \t]*\)\@160" 124 | 125 | " 126 | " Keywords 127 | " 128 | 129 | syn keyword pythonStatement break continue del 130 | syn keyword pythonStatement exec return 131 | syn keyword pythonStatement pass raise 132 | syn keyword pythonStatement global assert 133 | syn keyword pythonStatement lambda 134 | syn keyword pythonStatement with 135 | syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite 136 | syn keyword pythonRepeat for while 137 | syn keyword pythonConditional if elif else 138 | " Cython: removed 139 | " " The standard pyrex.vim unconditionally removes the pythonInclude group, so 140 | " " we provide a dummy group here to avoid crashing pyrex.vim. 141 | " syn keyword pythonInclude import 142 | syn keyword pythonImport import 143 | " Cython: removed 144 | " syn keyword pythonException try except finally 145 | syn keyword pythonException try finally 146 | syn keyword pythonOperator and in is not or 147 | 148 | syn match pythonStatement "\" display 149 | syn match pythonImport "\" display 150 | " Cython: added 151 | syn match pythonException "\?\?" 152 | 153 | if s:Python2Syntax() 154 | if !s:Enabled("g:python_print_as_function") 155 | syn keyword pythonStatement print 156 | endif 157 | syn keyword pythonImport as 158 | " Cython: removed 159 | " syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained 160 | else 161 | syn keyword pythonStatement as nonlocal None 162 | syn match pythonStatement "\" display 163 | syn keyword pythonBoolean True False 164 | " Cython: removed 165 | " syn match pythonFunction "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained 166 | syn keyword pythonStatement await 167 | syn match pythonStatement "\" nextgroup=pythonFunction skipwhite 168 | syn match pythonStatement "\" display 169 | syn match pythonStatement "\" display 170 | endif 171 | 172 | " Cython: added 173 | syn keyword pythonStatement const gil new nogil 174 | syn keyword pythonStatement cppclass enum struct union nextgroup=pythonFunction skipwhite 175 | syn keyword pythonStatement cpdef nextgroup=cythonType,pythonFunction skipwhite 176 | syn match pythonStatement "\v" nextgroup=cythonType,pythonFunction skipwhite 177 | syn match pythonStatement "\v" nextgroup=pythonFunction skipwhite 178 | syn keyword pythonConditional ELIF ELSE IF 179 | syn keyword pythonImport DEF 180 | syn keyword pythonImport cimport include 181 | syn match pythonImport "\v\ze\W*%(\:|\()" 190 | syn match cythonType 191 | \ "\v%(cdef\s+)@<=(\w|\.)+" 192 | 193 | " 194 | " Decorators (new in Python 2.4) 195 | " 196 | 197 | syn match pythonDecorator "^\s*\zs@" display nextgroup=pythonDottedName skipwhite 198 | if s:Python2Syntax() 199 | syn match pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained 200 | else 201 | syn match pythonDottedName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*" display contained 202 | endif 203 | syn match pythonDot "\." display containedin=pythonDottedName 204 | 205 | " 206 | " Comments 207 | " 208 | 209 | syn match pythonComment "#.*$" display contains=pythonTodo,@Spell 210 | if !s:Enabled("g:python_highlight_file_headers_as_comments") 211 | syn match pythonRun "\%^#!.*$" 212 | syn match pythonCoding "\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$" 213 | " Cython.Compiler.Parsing._match_compiler_directive_comment. 214 | syn match pythonDirective "\v^\#\s*cython\s*\:\s*((\w|\.)+\s*\=.*)$" 215 | " Cython.Build.Dependencies.DistutilsInfo.__init__. 216 | syn match pythonDirective "\v^\#\s*distutils:.*" 217 | endif 218 | syn keyword pythonTodo TODO FIXME XXX contained 219 | 220 | " 221 | " Errors 222 | " 223 | 224 | syn match pythonError "\<\d\+\D\+\>" display 225 | syn match pythonError "[$?]" display 226 | syn match pythonError "[&|]\{2,}" display 227 | syn match pythonError "[=]\{3,}" display 228 | 229 | " Mixing spaces and tabs also may be used for pretty formatting multiline 230 | " statements 231 | if s:Enabled("g:python_highlight_indent_errors") 232 | syn match pythonIndentError "^\s*\%( \t\|\t \)\s*\S"me=e-1 display 233 | endif 234 | 235 | " Trailing space errors 236 | if s:Enabled("g:python_highlight_space_errors") 237 | syn match pythonSpaceError "\s\+$" display 238 | endif 239 | 240 | " 241 | " Strings 242 | " 243 | 244 | if s:Python2Syntax() 245 | " Python 2 strings 246 | syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell 247 | syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell 248 | syn region pythonString start=+[bB]\="""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell 249 | syn region pythonString start=+[bB]\='''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell 250 | else 251 | " Python 3 byte strings 252 | syn region pythonBytes start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell 253 | syn region pythonBytes start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell 254 | syn region pythonBytes start=+[bB]"""+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell 255 | syn region pythonBytes start=+[bB]'''+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell 256 | 257 | syn match pythonBytesError ".\+" display contained 258 | syn match pythonBytesContent "[\u0000-\u00ff]\+" display contained contains=pythonBytesEscape,pythonBytesEscapeError 259 | endif 260 | 261 | syn match pythonBytesEscape +\\[abfnrtv'"\\]+ display contained 262 | syn match pythonBytesEscape "\\\o\o\=\o\=" display contained 263 | syn match pythonBytesEscapeError "\\\o\{,2}[89]" display contained 264 | syn match pythonBytesEscape "\\x\x\{2}" display contained 265 | syn match pythonBytesEscapeError "\\x\x\=\X" display contained 266 | syn match pythonBytesEscape "\\$" 267 | 268 | syn match pythonUniEscape "\\u\x\{4}" display contained 269 | syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained 270 | syn match pythonUniEscape "\\U\x\{8}" display contained 271 | syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained 272 | syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained 273 | syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained 274 | 275 | if s:Python2Syntax() 276 | " Python 2 Unicode strings 277 | syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell 278 | syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell 279 | syn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell 280 | syn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell 281 | else 282 | " Python 3 strings 283 | syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell 284 | syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell 285 | syn region pythonString start=+"""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell 286 | syn region pythonString start=+'''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell 287 | endif 288 | 289 | if s:Python2Syntax() 290 | " Python 2 Unicode raw strings 291 | syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell 292 | syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell 293 | syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell 294 | syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell 295 | 296 | syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained 297 | syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained 298 | endif 299 | 300 | " Python 2/3 raw strings 301 | if s:Python2Syntax() 302 | syn region pythonRawString start=+[bB]\=[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell 303 | syn region pythonRawString start=+[bB]\=[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell 304 | syn region pythonRawString start=+[bB]\=[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell 305 | syn region pythonRawString start=+[bB]\=[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell 306 | else 307 | syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell 308 | syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell 309 | syn region pythonRawString start=+[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell 310 | syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell 311 | 312 | syn region pythonRawBytes start=+[bB][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell 313 | syn region pythonRawBytes start=+[bB][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell 314 | syn region pythonRawBytes start=+[bB][rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell 315 | syn region pythonRawBytes start=+[bB][rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell 316 | endif 317 | 318 | syn match pythonRawEscape +\\['"]+ display transparent contained 319 | 320 | if s:Enabled("g:python_highlight_string_formatting") 321 | " % operator string formatting 322 | if s:Python2Syntax() 323 | syn match pythonStrFormatting "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString 324 | syn match pythonStrFormatting "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString 325 | else 326 | syn match pythonStrFormatting "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString 327 | syn match pythonStrFormatting "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString 328 | endif 329 | endif 330 | 331 | if s:Enabled("g:python_highlight_string_format") 332 | " str.format syntax 333 | if s:Python2Syntax() 334 | syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString 335 | syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString 336 | else 337 | syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString 338 | syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString 339 | endif 340 | endif 341 | 342 | if s:Enabled("g:python_highlight_string_templates") 343 | " string.Template format 344 | if s:Python2Syntax() 345 | syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString 346 | syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString 347 | syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString 348 | else 349 | syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonRawString 350 | syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonRawString 351 | syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonRawString 352 | endif 353 | endif 354 | 355 | if s:Enabled("g:python_highlight_doctests") 356 | " DocTests 357 | syn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained 358 | syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained 359 | endif 360 | 361 | " 362 | " Numbers (ints, longs, floats, complex) 363 | " 364 | 365 | if s:Python2Syntax() 366 | syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\+\x*[lL]\=\>" display 367 | syn match pythonOctError "\<0[oO]\=\o*\D\+\d*[lL]\=\>" display 368 | syn match pythonBinError "\<0[bB][01]*\D\+\d*[lL]\=\>" display 369 | 370 | syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" display 371 | syn match pythonOctNumber "\<0[oO]\o\+[lL]\=\>" display 372 | syn match pythonBinNumber "\<0[bB][01]\+[lL]\=\>" display 373 | 374 | syn match pythonNumberError "\<\d\+\D[lL]\=\>" display 375 | syn match pythonNumber "\<\d[lL]\=\>" display 376 | syn match pythonNumber "\<[0-9]\d\+[lL]\=\>" display 377 | syn match pythonNumber "\<\d\+[lLjJ]\>" display 378 | 379 | syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*[lL]\=\>" display 380 | syn match pythonBinError "\<0[bB][01]*[2-9]\d*[lL]\=\>" display 381 | else 382 | syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\x*\>" display 383 | syn match pythonOctError "\<0[oO]\=\o*\D\+\d*\>" display 384 | syn match pythonBinError "\<0[bB][01]*\D\+\d*\>" display 385 | 386 | syn match pythonHexNumber "\<0[xX]\x\+\>" display 387 | syn match pythonOctNumber "\<0[oO]\o\+\>" display 388 | syn match pythonBinNumber "\<0[bB][01]\+\>" display 389 | 390 | syn match pythonNumberError "\<\d\+\D\>" display 391 | syn match pythonNumberError "\<0\d\+\>" display 392 | syn match pythonNumber "\<\d\>" display 393 | syn match pythonNumber "\<[1-9]\d\+\>" display 394 | syn match pythonNumber "\<\d\+[jJ]\>" display 395 | 396 | syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*\>" display 397 | syn match pythonBinError "\<0[bB][01]*[2-9]\d*\>" display 398 | endif 399 | 400 | syn match pythonFloat "\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" display 401 | syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display 402 | syn match pythonFloat "\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=" display 403 | 404 | " 405 | " Builtin objects and types 406 | " 407 | 408 | if s:Enabled("g:python_highlight_builtin_objs") 409 | if s:Python2Syntax() 410 | syn keyword pythonBuiltinObj None 411 | syn keyword pythonBoolean True False 412 | endif 413 | syn keyword pythonBuiltinObj Ellipsis NotImplemented 414 | syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ __spec__ 415 | endif 416 | 417 | " 418 | " Builtin functions 419 | " 420 | 421 | if s:Enabled("g:python_highlight_builtin_funcs") 422 | if s:Python2Syntax() 423 | syn keyword pythonBuiltinFunc apply basestring buffer callable coerce 424 | \ execfile file help intern long raw_input 425 | \ reduce reload unichr unicode xrange 426 | \ contained containedin=pythonBuiltinIsolator 427 | if s:Enabled("g:python_print_as_function") 428 | syn keyword pythonBuiltinFunc print 429 | \ contained containedin=pythonBuiltinIsolator 430 | endif 431 | else 432 | syn keyword pythonBuiltinFunc ascii exec memoryview print 433 | \ contained containedin=pythonBuiltinIsolator 434 | endif 435 | syn keyword pythonBuiltinFunc __import__ abs all any 436 | \ bin bool bytearray bytes 437 | \ chr classmethod cmp compile complex 438 | \ delattr dict dir divmod enumerate eval 439 | \ filter float format frozenset getattr 440 | \ globals hasattr hash hex id 441 | \ input int isinstance 442 | \ issubclass iter len list locals map max 443 | \ min next object oct open ord 444 | \ pow property range 445 | \ repr reversed round set setattr 446 | \ slice sorted staticmethod str sum super tuple 447 | \ type vars zip 448 | \ contained containedin=pythonBuiltinIsolator 449 | endif 450 | 451 | " Cython: added (see Compiler/Parsing.py) 452 | syn keyword pythonBuiltinFunc NULL sizeof 453 | syn keyword cythonType void bint char short int long size_t ssize_t ptrdiff_t 454 | \ unsigned signed Py_hash_t Py_ssize_t Py_UNICODE Py_UCS4 455 | \ float double 456 | " Cython: define property statement here 457 | syn match pythonStatement "\v" nextgroup=pythonFunction skipwhite 458 | syn match pythonFunction "\%(property\s*\)\@<=\h\w*" contained 459 | 460 | " 461 | " Builtin exceptions and warnings 462 | " 463 | 464 | if s:Enabled("g:python_highlight_exceptions") 465 | if s:Python2Syntax() 466 | syn keyword pythonExClass StandardError contained containedin=pythonBuiltinIsolator 467 | else 468 | syn keyword pythonExClass BlockingIOError ChildProcessError 469 | \ ConnectionError BrokenPipeError 470 | \ ConnectionAbortedError ConnectionRefusedError 471 | \ ConnectionResetError FileExistsError 472 | \ FileNotFoundError InterruptedError 473 | \ IsADirectoryError NotADirectoryError 474 | \ PermissionError ProcessLookupError TimeoutError 475 | \ contained containedin=pythonBuiltinIsolator 476 | syn keyword pythonExClass ResourceWarning contained containedin=pythonBuiltinIsolator 477 | endif 478 | syn keyword pythonExClass BaseException 479 | \ Exception ArithmeticError 480 | \ LookupError EnvironmentError 481 | \ AssertionError AttributeError BufferError EOFError 482 | \ FloatingPointError GeneratorExit IOError 483 | \ ImportError IndexError KeyError 484 | \ KeyboardInterrupt MemoryError NameError 485 | \ NotImplementedError OSError OverflowError 486 | \ ReferenceError RuntimeError StopIteration 487 | \ SyntaxError IndentationError TabError 488 | \ SystemError SystemExit TypeError 489 | \ UnboundLocalError UnicodeError 490 | \ UnicodeEncodeError UnicodeDecodeError 491 | \ UnicodeTranslateError ValueError VMSError 492 | \ WindowsError ZeroDivisionError 493 | \ contained containedin=pythonBuiltinIsolator 494 | 495 | syn keyword pythonExClass Warning UserWarning BytesWarning DeprecationWarning 496 | \ PendingDepricationWarning SyntaxWarning 497 | \ RuntimeWarning FutureWarning 498 | \ ImportWarning UnicodeWarning 499 | \ contained containedin=pythonBuiltinIsolator 500 | end 501 | 502 | if s:Enabled("g:python_slow_sync") 503 | syn sync minlines=2000 504 | else 505 | " This is fast but code inside triple quoted strings screws it up. It 506 | " is impossible to fix because the only way to know if you are inside a 507 | " triple quoted string is to start from the beginning of the file. 508 | syn sync match pythonSync grouphere NONE "):$" 509 | syn sync maxlines=200 510 | endif 511 | 512 | if version >= 508 || !exists("did_python_syn_inits") 513 | if version <= 508 514 | let did_python_syn_inits = 1 515 | command -nargs=+ HiLink hi link 516 | else 517 | command -nargs=+ HiLink hi def link 518 | endif 519 | 520 | HiLink pythonStatement Statement 521 | HiLink pythonImport Include 522 | HiLink pythonFunction Function 523 | HiLink cythonType Function 524 | HiLink pythonConditional Conditional 525 | HiLink pythonRepeat Repeat 526 | HiLink pythonException Exception 527 | HiLink pythonOperator Operator 528 | 529 | HiLink pythonDecorator Define 530 | HiLink pythonDottedName Function 531 | HiLink pythonDot Normal 532 | 533 | HiLink pythonComment Comment 534 | if !s:Enabled("g:python_highlight_file_headers_as_comments") 535 | HiLink pythonCoding Special 536 | HiLink pythonRun Special 537 | HiLink pythonDirective Special 538 | endif 539 | HiLink pythonTodo Todo 540 | 541 | HiLink pythonError Error 542 | HiLink pythonIndentError Error 543 | HiLink pythonSpaceError Error 544 | 545 | HiLink pythonString String 546 | HiLink pythonRawString String 547 | 548 | HiLink pythonUniEscape Special 549 | HiLink pythonUniEscapeError Error 550 | 551 | if s:Python2Syntax() 552 | HiLink pythonUniString String 553 | HiLink pythonUniRawString String 554 | HiLink pythonUniRawEscape Special 555 | HiLink pythonUniRawEscapeError Error 556 | else 557 | HiLink pythonBytes String 558 | HiLink pythonRawBytes String 559 | HiLink pythonBytesContent String 560 | HiLink pythonBytesError Error 561 | HiLink pythonBytesEscape Special 562 | HiLink pythonBytesEscapeError Error 563 | endif 564 | 565 | HiLink pythonStrFormatting Special 566 | HiLink pythonStrFormat Special 567 | HiLink pythonStrTemplate Special 568 | 569 | HiLink pythonDocTest Special 570 | HiLink pythonDocTest2 Special 571 | 572 | HiLink pythonNumber Number 573 | HiLink pythonHexNumber Number 574 | HiLink pythonOctNumber Number 575 | HiLink pythonBinNumber Number 576 | HiLink pythonFloat Float 577 | HiLink pythonNumberError Error 578 | HiLink pythonOctError Error 579 | HiLink pythonHexError Error 580 | HiLink pythonBinError Error 581 | 582 | HiLink pythonBoolean Boolean 583 | 584 | HiLink pythonBuiltinObj Structure 585 | HiLink pythonBuiltinFunc Function 586 | 587 | HiLink pythonExClass Structure 588 | 589 | delcommand HiLink 590 | endif 591 | 592 | let b:current_syntax = "cython" 593 | --------------------------------------------------------------------------------