Start anew
[msysgit.git] / share / vim / vim58 / syntax / python.vim
blobfb0cd26b761d9bfe6f033bca81f9dc0e02ce0550
1 " Vim syntax file
2 " Language:     Python
3 " Maintainer:   Neil Schemenauer <nas@python.ca>
4 " Updated:      2001-05-13
6 " There are four options to control Python syntax highlighting.
8 " For highlighted numbers:
10 "    let python_highlight_numbers = 1
12 " For highlighted builtin functions:
14 "    let python_highlight_builtins = 1
16 " For highlighted standard exceptions:
18 "    let python_highlight_exceptions = 1
20 " If you want all possible Python highlighting (the same as setting the
21 " preceding three options):
23 "    let python_highlight_all = 1
26 " For version 5.x: Clear all syntax items
27 " For version 6.x: Quit when a syntax file was already loaded
28 if version < 600
29   syntax clear
30 elseif exists("b:current_syntax")
31   finish
32 endif
35 syn keyword pythonStatement     break continue del
36 syn keyword pythonStatement     except exec finally
37 syn keyword pythonStatement     pass print raise
38 syn keyword pythonStatement     return try
39 syn keyword pythonStatement     global assert
40 syn keyword pythonStatement     lambda
41 syn keyword pythonStatement     def class nextgroup=pythonFunction skipwhite
42 syn match   pythonFunction      "[a-zA-Z_][a-zA-Z0-9_]*" contained
43 syn keyword pythonRepeat        for while
44 syn keyword pythonConditional   if elif else
45 syn keyword pythonOperator      and in is not or
46 syn keyword pythonPreCondit     import from
47 syn match   pythonComment       "#.*$" contains=pythonTodo
48 syn keyword pythonTodo          contained TODO FIXME XXX
50 " strings
51 syn region pythonString         matchgroup=Normal start=+'+  end=+'+ skip=+\\\\\|\\'+ contains=pythonEscape
52 syn region pythonString         matchgroup=Normal start=+"+  end=+"+ skip=+\\\\\|\\"+ contains=pythonEscape
53 syn region pythonString         matchgroup=Normal start=+"""+  end=+"""+ contains=pythonEscape
54 syn region pythonString         matchgroup=Normal start=+'''+  end=+'''+ contains=pythonEscape
55 syn region pythonRawString      matchgroup=Normal start=+[rR]'+ end=+'+ skip=+\\\\\|\\'+
56 syn region pythonRawString      matchgroup=Normal start=+[rR]"+    end=+"+ skip=+\\\\\|\\"+
57 syn region pythonRawString      matchgroup=Normal start=+[rR]"""+ end=+"""+
58 syn region pythonRawString      matchgroup=Normal start=+[rR]'''+ end=+'''+
59 syn match  pythonEscape         +\\[abfnrtv'"\\]+ contained
60 syn match  pythonEscape         "\\\o\o\=\o\=" contained
61 syn match  pythonEscape         "\\x\x\+" contained
62 syn match  pythonEscape         "\\$"
64 if exists("python_highlight_all")
65   let python_highlight_numbers = 1
66   let python_highlight_builtins = 1
67   let python_highlight_exceptions = 1
68 endif
70 if exists("python_highlight_numbers")
71   " numbers (including longs and complex)
72   syn match   pythonNumber      "\<0x\x\+[Ll]\=\>"
73   syn match   pythonNumber      "\<\d\+[LljJ]\=\>"
74   syn match   pythonNumber      "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>"
75   syn match   pythonNumber      "\<\d\+\.\([eE][+-]\=\d\+\)\=[jJ]\=\>"
76   syn match   pythonNumber      "\<\d\+\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>"
77 endif
79 if exists("python_highlight_builtins")
80   " builtin functions, not really part of the syntax
81   syn keyword pythonBuiltin     abs apply callable chr cmp coerce
82   syn keyword pythonBuiltin     compile complex delattr dir divmod
83   syn keyword pythonBuiltin     eval execfile filter float getattr
84   syn keyword pythonBuiltin     globals hasattr hash hex id input
85   syn keyword pythonBuiltin     int intern isinstance issubclass
86   syn keyword pythonBuiltin     len list locals long map max min
87   syn keyword pythonBuiltin     oct open ord pow range raw_input
88   syn keyword pythonBuiltin     reduce reload repr round setattr
89   syn keyword pythonBuiltin     slice str tuple type vars xrange
90 endif
92 if exists("python_highlight_exceptions")
93   " builtin exceptions
94   syn keyword pythonException   ArithmeticError AssertionError
95   syn keyword pythonException   AttributeError EOFError EnvironmentError
96   syn keyword pythonException   Exception FloatingPointError IOError
97   syn keyword pythonException   ImportError IndexError KeyError
98   syn keyword pythonException   KeyboardInterrupt LookupError
99   syn keyword pythonException   MemoryError NameError NotImplementedError
100   syn keyword pythonException   OSError OverflowError RuntimeError
101   syn keyword pythonException   StandardError SyntaxError SystemError
102   syn keyword pythonException   SystemExit TypeError ValueError
103   syn keyword pythonException   ZeroDivisionError
104 endif
107 " This is fast but code inside triple quoted strings screws it up. It
108 " is impossible to fix because the only way to know if you are inside a
109 " triple quoted string is to start from the beginning of the file. If
110 " you have a fast machine you can try uncommenting the "sync minlines"
111 " and commenting out the rest.
112 syn sync match pythonSync grouphere NONE "):$"
113 syn sync maxlines=200
114 "syn sync minlines=2000
116 if version >= 508 || !exists("did_python_syn_inits")
117   if version <= 508
118     let did_python_syn_inits = 1
119     command -nargs=+ HiLink hi link <args>
120   else
121     command -nargs=+ HiLink hi def link <args>
122   endif
124   " The default methods for highlighting.  Can be overridden later
125   HiLink pythonStatement        Statement
126   HiLink pythonFunction         Function
127   HiLink pythonConditional      Conditional
128   HiLink pythonRepeat           Repeat
129   HiLink pythonString           String
130   HiLink pythonRawString        String
131   HiLink pythonEscape           Special
132   HiLink pythonOperator         Operator
133   HiLink pythonPreCondit        PreCondit
134   HiLink pythonComment          Comment
135   HiLink pythonTodo             Todo
136   if exists("python_highlight_numbers")
137     HiLink pythonNumber Number
138   endif
139   if exists("python_highlight_builtins")
140     HiLink pythonBuiltin        Function
141   endif
142   if exists("python_highlight_exceptions")
143     HiLink pythonException      Exception
144   endif
146   delcommand HiLink
147 endif
149 let b:current_syntax = "python"
151 " vim: ts=8