22" Language: Python
33" Maintainer: Dmitry Vasiliev <dima@hlabs.spb.ru>
44" URL: http://www.hlabs.spb.ru/vim/python.vim
5- " Last Change: 2008-09-21
5+ " Last Change: 2008-12-07
66" Filenames: *.py
7- " Version: 2.6.1
7+ " Version: 3.0.0
88"
99" Based on python.vim (from Vim 6.1 distribution)
1010" by Neil Schemenauer <nas@python.ca>
@@ -103,7 +103,7 @@ syn keyword pythonStatement lambda yield
103103syn keyword pythonStatement with nonlocal
104104syn keyword pythonStatement False None True
105105syn keyword pythonStatement def class nextgroup =pythonFunction skipwhite
106- syn match pythonFunction " [a-zA-Z_][a-zA-Z0-9_] *" display contained
106+ syn match pythonFunction " \% ([^[:cntrl:][:space:][:punct:][:digit:]] \| _ \)\% ([^[:cntrl:][:punct:][:space:]] \| _ \) *" display contained
107107syn keyword pythonRepeat for while
108108syn keyword pythonConditional if elif else
109109syn keyword pythonImport import from
@@ -116,7 +116,7 @@ syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite
116116" Comments
117117syn match pythonComment " #.*$" display contains =pythonTodo,@Spell
118118syn match pythonRun " \% ^#!.*$"
119- syn match pythonCoding " \% ^.*\(\n .*\)\? #.*coding[:=]\s *[0-9A-Za-z-_.]\+ .*$"
119+ syn match pythonCoding " \% ^.*\% (\n .*\)\? #.*coding[:=]\s *[0-9A-Za-z-_.]\+ .*$"
120120syn keyword pythonTodo TODO FIXME XXX contained
121121
122122" Errors
@@ -128,7 +128,7 @@ syn match pythonError "[=]\{3,}" display
128128" TODO: Mixing spaces and tabs also may be used for pretty formatting multiline
129129" statements. For now I don't know how to work around this.
130130if exists (" python_highlight_indent_errors" ) && python_highlight_indent_errors != 0
131- syn match pythonIndentError " ^\s *\( \t\|\t \)\s *\S " me =e - 1 display
131+ syn match pythonIndentError " ^\s *\% ( \t\|\t \)\s *\S " me =e - 1 display
132132endif
133133
134134" Trailing space errors
@@ -142,25 +142,18 @@ syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+
142142syn region pythonString start =+ """+ end =+ """+ keepend contains =pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell
143143syn region pythonString start =+ '''+ end =+ '''+ keepend contains =pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceError,@Spell
144144
145- syn match pythonEscape + \\ [abfnrtv'"\\ ]+ display contained
146- syn match pythonEscape " \\\o\o\=\o\= " display contained
145+ syn match pythonEscape + \\ [abfnrtv'"\\ ]+ display contained
146+ syn match pythonEscape " \\\o\o\=\o\= " display contained
147147syn match pythonEscapeError " \\\o\{ ,2}[89]" display contained
148- syn match pythonEscape " \\ x\x\{ 2}" display contained
148+ syn match pythonEscape " \\ x\x\{ 2}" display contained
149149syn match pythonEscapeError " \\ x\x\=\X " display contained
150- syn match pythonEscape " \\ $"
151-
152- " Unicode strings
153- syn region pythonUniString start =+ [uU]'+ skip =+ \\\\\|\\ '\|\\ $+ excludenl end =+ '+ end =+ $+ keepend contains =pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
154- syn region pythonUniString start =+ [uU]"+ skip =+ \\\\\|\\ "\|\\ $+ excludenl end =+ "+ end =+ $+ keepend contains =pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
155- syn region pythonUniString start =+ [uU]"""+ end =+ """+ keepend contains =pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
156- syn region pythonUniString start =+ [uU]'''+ end =+ '''+ keepend contains =pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
157-
158- syn match pythonUniEscape " \\ u\x\{ 4}" display contained
159- syn match pythonUniEscapeError " \\ u\x\{ ,3}\X " display contained
160- syn match pythonUniEscape " \\ U\x\{ 8}" display contained
161- syn match pythonUniEscapeError " \\ U\x\{ ,7}\X " display contained
162- syn match pythonUniEscape " \\ N{[A-Z ]\+ }" display contained
163- syn match pythonUniEscapeError " \\ N{[^A-Z ]\+ }" display contained
150+ syn match pythonEscape " \\ $"
151+ syn match pythonEscape " \\ u\x\{ 4}" display contained
152+ syn match pythonEscapeError " \\ u\x\{ ,3}\X " display contained
153+ syn match pythonEscape " \\ U\x\{ 8}" display contained
154+ syn match pythonEscapeError " \\ U\x\{ ,7}\X " display contained
155+ syn match pythonEscape " \\ N{[A-Z ]\+ }" display contained
156+ syn match pythonEscapeError " \\ N{[^A-Z ]\+ }" display contained
164157
165158" Raw strings
166159syn region pythonRawString start =+ [rR]'+ skip =+ \\\\\|\\ '\|\\ $+ excludenl end =+ '+ end =+ $+ keepend contains =pythonRawEscape,@Spell
@@ -170,32 +163,39 @@ syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocT
170163
171164syn match pythonRawEscape + \\ ['"]+ display transparent contained
172165
173- " Unicode raw strings
174- syn region pythonUniRawString start =+ [uU][rR]'+ skip =+ \\\\\|\\ '\|\\ $+ excludenl end =+ '+ end =+ $+ keepend contains =pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
175- syn region pythonUniRawString start =+ [uU][rR]"+ skip =+ \\\\\|\\ "\|\\ $+ excludenl end =+ "+ end =+ $+ keepend contains =pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
176- syn region pythonUniRawString start =+ [uU][rR]"""+ end =+ """+ keepend contains =pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell
177- syn region pythonUniRawString start =+ [uU][rR]'''+ end =+ '''+ keepend contains =pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell
166+ " Bytes
167+ syn region pythonBytes start =+ [bB]'+ skip =+ \\\\\|\\ '\|\\ $+ excludenl end =+ '+ end =+ $+ keepend contains =pythonBytesContent,pythonBytesError,pythonBytesEscape,pythonBytesEscapeError,@Spell
168+ syn region pythonBytes start =+ [bB]"+ skip =+ \\\\\|\\ "\|\\ $+ excludenl end =+ "+ end =+ $+ keepend contains =pythonBytesContent,pythonBytesError,pythonBytesEscape,pythonBytesEscapeError,@Spell
169+ syn region pythonBytes start =+ [bB]"""+ end =+ """+ keepend contains =pythonBytesContent,pythonBytesError,pythonBytesEscape,pythonBytesEscapeError,pythonDocTest2,pythonSpaceError,@Spell
170+ syn region pythonBytes start =+ [bB]'''+ end =+ '''+ keepend contains =pythonBytesContent,pythonBytesError,pythonBytesEscape,pythonBytesEscapeError,pythonDocTest,pythonSpaceError,@Spell
171+
172+ syn match pythonBytesContent " [\u 0001-\u 007f]\+ " display contained
173+ syn match pythonBytesError " [^\u 0001-\u 007f]\+ " display contained
178174
179- syn match pythonUniRawEscape " \( [^\\ ]\(\\\\\) *\)\@ <=\\ u\x\{ 4}" display contained
180- syn match pythonUniRawEscapeError " \( [^\\ ]\(\\\\\) *\)\@ <=\\ u\x\{ ,3}\X " display contained
175+ syn match pythonBytesEscape + \\ [abfnrtv'"\\ ]+ display contained
176+ syn match pythonBytesEscape " \\\o\o\=\o\= " display contained
177+ syn match pythonBytesEscapeError " \\\o\{ ,2}[89]" display contained
178+ syn match pythonBytesEscape " \\ x\x\{ 2}" display contained
179+ syn match pythonBytesEscapeError " \\ x\x\=\X " display contained
180+ syn match pythonBytesEscape " \\ $"
181181
182182if exists (" python_highlight_string_formatting" ) && python_highlight_string_formatting != 0
183183 " String formatting
184- syn match pythonStrFormatting " %\( ([^)]\+ )\)\= [-#0 +]*\d *\(\.\d\+\)\= [hlL]\= [diouxXeEfFgGcrs%]" contained containedin =pythonString,pythonUniString, pythonRawString,pythonUniRawString
185- syn match pythonStrFormatting " %[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\= [hlL]\= [diouxXeEfFgGcrs%]" contained containedin =pythonString,pythonUniString, pythonRawString,pythonUniRawString
184+ syn match pythonStrFormatting " %\% (([^)]\+ )\)\= [-#0 +]*\d *\% (\.\d\+\)\= [hlL]\= [diouxXeEfFgGcrs%]" contained containedin =pythonString,pythonRawString
185+ syn match pythonStrFormatting " %[-#0 +]*\% (\*\|\d\+\)\=\% (\.\% (\*\|\d\+\)\)\= [hlL]\= [diouxXeEfFgGcrs%]" contained containedin =pythonString,pythonRawString
186186endif
187187
188188if exists (" python_highlight_string_format" ) && python_highlight_string_format != 0
189189 " str.format syntax
190- syn match pythonStrFormat " {{\| }}" contained containedin =pythonString,pythonUniString, pythonRawString,pythonUniRawString
191- syn match pythonStrFormat " {\( [a-zA-Z_][a-zA-Z0-9_] *\|\d\+\)\(\. [a-zA-Z_][a-zA-Z0-9_]* \ |\[\(\d\+\| [^!:\} ]\+\)\]\) *\( ![rsa]\)\=\( :\( {\( [a-zA-Z_][a-zA-Z0-9_] *\|\d\+\) }\|\( [^}]\= [<>=^]\)\= [ +-]\= #\= 0\=\d *\(\.\d\+\)\= [bcdeEfFgGnoxX%]\=\)\=\)\= }" contained containedin =pythonString,pythonUniString, pythonRawString,pythonUniRawString
190+ syn match pythonStrFormat " {{\| }}" contained containedin =pythonString,pythonRawString
191+ 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\+\)\= [bcdeEfFgGnoxX%]\=\)\=\)\= }" contained containedin =pythonString,pythonRawString
192192endif
193193
194194if exists (" python_highlight_string_templates" ) && python_highlight_string_templates != 0
195195 " String templates
196- syn match pythonStrTemplate " \$\$ " contained containedin =pythonString,pythonUniString, pythonRawString,pythonUniRawString
197- syn match pythonStrTemplate " \$ {[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin =pythonString,pythonUniString, pythonRawString,pythonUniRawString
198- syn match pythonStrTemplate " \$ [a-zA-Z_][a-zA-Z0-9_]*" contained containedin =pythonString,pythonUniString, pythonRawString,pythonUniRawString
196+ syn match pythonStrTemplate " \$\$ " contained containedin =pythonString,pythonRawString
197+ syn match pythonStrTemplate " \$ {[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin =pythonString,pythonRawString
198+ syn match pythonStrTemplate " \$ [a-zA-Z_][a-zA-Z0-9_]*" contained containedin =pythonString,pythonRawString
199199endif
200200
201201if exists (" python_highlight_doctests" ) && python_highlight_doctests != 0
@@ -211,11 +211,14 @@ syn match pythonHexNumber "\<0[xX]\x\+\>" display
211211syn match pythonOctNumber " \< 0[oO]\o\+\> " display
212212syn match pythonBinNumber " \< 0[bB][01]\+\> " display
213213
214- syn match pythonNumber " \<\d\+ [jJ]\=\> " display
214+ syn match pythonNumber " \< 0\> " display
215+ syn match pythonNumber " \< [1-9]\d\+\> " display
216+ syn match pythonNumber " \<\d\+ [jJ]\> " display
217+ syn match pythonNumberError " \< 0\d\+\> " display
215218
216- syn match pythonFloat " \.\d\+\( [eE][+-]\=\d\+\)\= [jJ]\=\> " display
219+ syn match pythonFloat " \.\d\+\% ([eE][+-]\=\d\+\)\= [jJ]\=\> " display
217220syn match pythonFloat " \<\d\+ [eE][+-]\=\d\+ [jJ]\=\> " display
218- syn match pythonFloat " \<\d\+\.\d *\( [eE][+-]\=\d\+\)\= [jJ]\= " display
221+ syn match pythonFloat " \<\d\+\.\d *\% ([eE][+-]\=\d\+\)\= [jJ]\= " display
219222
220223syn match pythonOctError " \< 0[oO]\=\o *[8-9]\d *\> " display
221224syn match pythonBinError " \< 0[bB][01]*[2-9]\d *\> " display
@@ -303,16 +306,15 @@ if version >= 508 || !exists("did_python_syn_inits")
303306 HiLink pythonSpaceError Error
304307
305308 HiLink pythonString String
306- HiLink pythonUniString String
307309 HiLink pythonRawString String
308- HiLink pythonUniRawString String
309-
310310 HiLink pythonEscape Special
311311 HiLink pythonEscapeError Error
312- HiLink pythonUniEscape Special
313- HiLink pythonUniEscapeError Error
314- HiLink pythonUniRawEscape Special
315- HiLink pythonUniRawEscapeError Error
312+
313+ HiLink pythonBytes String
314+ HiLink pythonBytesContent String
315+ HiLink pythonBytesError Error
316+ HiLink pythonBytesEscape Special
317+ HiLink pythonBytesEscapeError Error
316318
317319 HiLink pythonStrFormatting Special
318320 HiLink pythonStrFormat Special
@@ -326,6 +328,7 @@ if version >= 508 || !exists("did_python_syn_inits")
326328 HiLink pythonOctNumber Number
327329 HiLink pythonBinNumber Number
328330 HiLink pythonFloat Float
331+ HiLink pythonNumberError Error
329332 HiLink pythonOctError Error
330333 HiLink pythonHexError Error
331334 HiLink pythonBinError Error
0 commit comments