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