Skip to content

Commit 4954174

Browse files
committed
Added support for b'...' syntax
1 parent 62f6125 commit 4954174

File tree

5 files changed

+368
-7
lines changed

5 files changed

+368
-7
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Revision 2.6.2 (2008-09-?):
2+
3+
- Added support for b"..." syntax;
4+
15
Revision 2.6.1 (2008-09-21):
26

37
- Added new builtins and exceptions introduced in Python 2.6: "bin",

TODO.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Now
22
===
33

4+
- (Python 3.0) support for b"..." syntax and remove u"..." syntax;
5+
6+
- (Python 3.0) add new bultins and exceptions;
7+
48
Later
59
=====
610

python.vim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
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-09-22
66
" Filenames: *.py
7-
" Version: 2.6.1
7+
" Version: 2.6.2
88
"
99
" Based on python.vim (from Vim 6.1 distribution)
1010
" by Neil Schemenauer <nas@python.ca>
@@ -143,10 +143,10 @@ if exists("python_highlight_space_errors") && python_highlight_space_errors != 0
143143
endif
144144

145145
" Strings
146-
syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
147-
syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
148-
syn region pythonString start=+"""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell
149-
syn region pythonString start=+'''+ end=+'''+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceError,@Spell
146+
syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
147+
syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
148+
syn region pythonString start=+[bB]\="""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell
149+
syn region pythonString start=+[bB]\='''+ end=+'''+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceError,@Spell
150150

151151
syn match pythonEscape +\\[abfnrtv'"\\]+ display contained
152152
syn match pythonEscape "\\\o\o\=\o\=" display contained

python3.0.vim

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

0 commit comments

Comments
 (0)