annotate runtime/syntax/python.vim @ 2015:89189f7aaad9 v7.2.312

updated for version 7.2-312
author vimboss
date Wed, 02 Dec 2009 14:02:39 +0000
parents 96cd8222a819
children 7bc41231fbc7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim syntax file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: Python
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Maintainer: Neil Schemenauer <nas@python.ca>
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 874
diff changeset
4 " Updated: 2006-10-15
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 859
diff changeset
5 " Added Python 2.4 features 2006 May 4 (Dmitry Vasiliev)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 " Options to control Python syntax highlighting:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 " For highlighted numbers:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 " let python_highlight_numbers = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 " For highlighted builtin functions:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 " let python_highlight_builtins = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 " For highlighted standard exceptions:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 " let python_highlight_exceptions = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 " Highlight erroneous whitespace:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 " let python_highlight_space_errors = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 " If you want all possible Python highlighting (the same as setting the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 " preceding options):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 " let python_highlight_all = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 " For version 5.x: Clear all syntax items
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 " For version 6.x: Quit when a syntax file was already loaded
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 if version < 600
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 syntax clear
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 elseif exists("b:current_syntax")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 syn keyword pythonStatement break continue del
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 syn keyword pythonStatement except exec finally
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 syn keyword pythonStatement pass print raise
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 874
diff changeset
43 syn keyword pythonStatement return try with
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 syn keyword pythonStatement global assert
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 syn keyword pythonStatement lambda yield
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" contained
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 syn keyword pythonRepeat for while
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 syn keyword pythonConditional if elif else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 syn keyword pythonOperator and in is not or
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 7
diff changeset
51 " AS will be a keyword in Python 3
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 7
diff changeset
52 syn keyword pythonPreCondit import from as
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 874
diff changeset
53 syn match pythonComment "#.*$" contains=pythonTodo,@Spell
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 syn keyword pythonTodo TODO FIXME XXX contained
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
859
99305c4c42d4 updated for version 7.0g02
vimboss
parents: 818
diff changeset
56 " Decorators (new in Python 2.4)
99305c4c42d4 updated for version 7.0g02
vimboss
parents: 818
diff changeset
57 syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite
99305c4c42d4 updated for version 7.0g02
vimboss
parents: 818
diff changeset
58
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 " strings
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 874
diff changeset
60 syn region pythonString matchgroup=Normal start=+[uU]\='+ end=+'+ skip=+\\\\\|\\'+ contains=pythonEscape,@Spell
96cd8222a819 updated for version 7.1a
vimboss
parents: 874
diff changeset
61 syn region pythonString matchgroup=Normal start=+[uU]\="+ end=+"+ skip=+\\\\\|\\"+ contains=pythonEscape,@Spell
96cd8222a819 updated for version 7.1a
vimboss
parents: 874
diff changeset
62 syn region pythonString matchgroup=Normal start=+[uU]\="""+ end=+"""+ contains=pythonEscape,@Spell
96cd8222a819 updated for version 7.1a
vimboss
parents: 874
diff changeset
63 syn region pythonString matchgroup=Normal start=+[uU]\='''+ end=+'''+ contains=pythonEscape,@Spell
96cd8222a819 updated for version 7.1a
vimboss
parents: 874
diff changeset
64 syn region pythonRawString matchgroup=Normal start=+[uU]\=[rR]'+ end=+'+ skip=+\\\\\|\\'+ contains=@Spell
96cd8222a819 updated for version 7.1a
vimboss
parents: 874
diff changeset
65 syn region pythonRawString matchgroup=Normal start=+[uU]\=[rR]"+ end=+"+ skip=+\\\\\|\\"+ contains=@Spell
96cd8222a819 updated for version 7.1a
vimboss
parents: 874
diff changeset
66 syn region pythonRawString matchgroup=Normal start=+[uU]\=[rR]"""+ end=+"""+ contains=@Spell
96cd8222a819 updated for version 7.1a
vimboss
parents: 874
diff changeset
67 syn region pythonRawString matchgroup=Normal start=+[uU]\=[rR]'''+ end=+'''+ contains=@Spell
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 syn match pythonEscape +\\[abfnrtv'"\\]+ contained
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 syn match pythonEscape "\\\o\{1,3}" contained
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 syn match pythonEscape "\\x\x\{2}" contained
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 syn match pythonEscape "\(\\u\x\{4}\|\\U\x\{8}\)" contained
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 syn match pythonEscape "\\$"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 if exists("python_highlight_all")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 let python_highlight_numbers = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 let python_highlight_builtins = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 let python_highlight_exceptions = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 let python_highlight_space_errors = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 if exists("python_highlight_numbers")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 " numbers (including longs and complex)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 syn match pythonNumber "\<0x\x\+[Ll]\=\>"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 syn match pythonNumber "\<\d\+[LljJ]\=\>"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 syn match pythonNumber "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 syn match pythonNumber "\<\d\+\.\([eE][+-]\=\d\+\)\=[jJ]\=\>"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 syn match pythonNumber "\<\d\+\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 if exists("python_highlight_builtins")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 " builtin functions, types and objects, not really part of the syntax
859
99305c4c42d4 updated for version 7.0g02
vimboss
parents: 818
diff changeset
92 syn keyword pythonBuiltin True False bool enumerate set frozenset help
99305c4c42d4 updated for version 7.0g02
vimboss
parents: 818
diff changeset
93 syn keyword pythonBuiltin reversed sorted sum
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 syn keyword pythonBuiltin Ellipsis None NotImplemented __import__ abs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 syn keyword pythonBuiltin apply buffer callable chr classmethod cmp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 syn keyword pythonBuiltin coerce compile complex delattr dict dir divmod
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 syn keyword pythonBuiltin eval execfile file filter float getattr globals
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 syn keyword pythonBuiltin hasattr hash hex id input int intern isinstance
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 syn keyword pythonBuiltin issubclass iter len list locals long map max
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 syn keyword pythonBuiltin min object oct open ord pow property range
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 syn keyword pythonBuiltin raw_input reduce reload repr round setattr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 syn keyword pythonBuiltin slice staticmethod str super tuple type unichr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 syn keyword pythonBuiltin unicode vars xrange zip
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 if exists("python_highlight_exceptions")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 " builtin exceptions and warnings
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 syn keyword pythonException ArithmeticError AssertionError AttributeError
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 syn keyword pythonException DeprecationWarning EOFError EnvironmentError
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 syn keyword pythonException Exception FloatingPointError IOError
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 syn keyword pythonException ImportError IndentationError IndexError
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 syn keyword pythonException KeyError KeyboardInterrupt LookupError
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 syn keyword pythonException MemoryError NameError NotImplementedError
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 syn keyword pythonException OSError OverflowError OverflowWarning
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 syn keyword pythonException ReferenceError RuntimeError RuntimeWarning
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 syn keyword pythonException StandardError StopIteration SyntaxError
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 syn keyword pythonException SyntaxWarning SystemError SystemExit TabError
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 syn keyword pythonException TypeError UnboundLocalError UnicodeError
859
99305c4c42d4 updated for version 7.0g02
vimboss
parents: 818
diff changeset
119 syn keyword pythonException UnicodeEncodeError UnicodeDecodeError
99305c4c42d4 updated for version 7.0g02
vimboss
parents: 818
diff changeset
120 syn keyword pythonException UnicodeTranslateError
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 syn keyword pythonException UserWarning ValueError Warning WindowsError
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 syn keyword pythonException ZeroDivisionError
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 if exists("python_highlight_space_errors")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 " trailing whitespace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 syn match pythonSpaceError display excludenl "\S\s\+$"ms=s+1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 " mixed tabs and spaces
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 syn match pythonSpaceError display " \+\t"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 syn match pythonSpaceError display "\t\+ "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 " This is fast but code inside triple quoted strings screws it up. It
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 " is impossible to fix because the only way to know if you are inside a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 " triple quoted string is to start from the beginning of the file. If
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 " you have a fast machine you can try uncommenting the "sync minlines"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 " and commenting out the rest.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 syn sync match pythonSync grouphere NONE "):$"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 syn sync maxlines=200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 "syn sync minlines=2000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 if version >= 508 || !exists("did_python_syn_inits")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 if version <= 508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 let did_python_syn_inits = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 command -nargs=+ HiLink hi link <args>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 command -nargs=+ HiLink hi def link <args>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 " The default methods for highlighting. Can be overridden later
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 HiLink pythonStatement Statement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 HiLink pythonFunction Function
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 HiLink pythonConditional Conditional
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 HiLink pythonRepeat Repeat
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 HiLink pythonString String
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 HiLink pythonRawString String
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 HiLink pythonEscape Special
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 HiLink pythonOperator Operator
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 HiLink pythonPreCondit PreCondit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 HiLink pythonComment Comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 HiLink pythonTodo Todo
859
99305c4c42d4 updated for version 7.0g02
vimboss
parents: 818
diff changeset
162 HiLink pythonDecorator Define
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 if exists("python_highlight_numbers")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 HiLink pythonNumber Number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 if exists("python_highlight_builtins")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 HiLink pythonBuiltin Function
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 if exists("python_highlight_exceptions")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 HiLink pythonException Exception
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 if exists("python_highlight_space_errors")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 HiLink pythonSpaceError Error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 delcommand HiLink
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 let b:current_syntax = "python"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 " vim: ts=8