Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Python |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 3 | " Maintainer: Zvezdan Petkovic <zpetkovic@acm.org> |
Bram Moolenaar | e4a3bcf | 2016-08-26 19:52:37 +0200 | [diff] [blame] | 4 | " Last Change: 2016 Aug 14 |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 5 | " Credits: Neil Schemenauer <nas@python.ca> |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6 | " Dmitry Vasiliev |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7 | " |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8 | " This version is a major rewrite by Zvezdan Petkovic. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9 | " |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 10 | " - introduced highlighting of doctests |
| 11 | " - updated keywords, built-ins, and exceptions |
| 12 | " - corrected regular expressions for |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 13 | " |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 14 | " * functions |
| 15 | " * decorators |
| 16 | " * strings |
| 17 | " * escapes |
| 18 | " * numbers |
| 19 | " * space error |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 20 | " |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 21 | " - corrected synchronization |
| 22 | " - more highlighting is ON by default, except |
| 23 | " - space error highlighting is OFF by default |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 24 | " |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 25 | " Optional highlighting can be controlled using these variables. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 26 | " |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 27 | " let python_no_builtin_highlight = 1 |
| 28 | " let python_no_doctest_code_highlight = 1 |
| 29 | " let python_no_doctest_highlight = 1 |
| 30 | " let python_no_exception_highlight = 1 |
| 31 | " let python_no_number_highlight = 1 |
| 32 | " let python_space_error_highlight = 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 33 | " |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 34 | " All the options above can be switched on together. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 35 | " |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 36 | " let python_highlight_all = 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 37 | " |
| 38 | |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 39 | " quit when a syntax file was already loaded. |
| 40 | if exists("b:current_syntax") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 41 | finish |
| 42 | endif |
| 43 | |
Bram Moolenaar | 0065906 | 2010-09-21 22:34:02 +0200 | [diff] [blame] | 44 | " We need nocompatible mode in order to continue lines with backslashes. |
| 45 | " Original setting will be restored. |
| 46 | let s:cpo_save = &cpo |
| 47 | set cpo&vim |
| 48 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 49 | " Keep Python keywords in alphabetical order inside groups for easy |
| 50 | " comparison with the table in the 'Python Language Reference' |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 51 | " https://docs.python.org/2/reference/lexical_analysis.html#keywords, |
| 52 | " https://docs.python.org/3/reference/lexical_analysis.html#keywords. |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 53 | " Groups are in the order presented in NAMING CONVENTIONS in syntax.txt. |
| 54 | " Exceptions come last at the end of each group (class and def below). |
| 55 | " |
| 56 | " Keywords 'with' and 'as' are new in Python 2.6 |
| 57 | " (use 'from __future__ import with_statement' in Python 2.5). |
| 58 | " |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 59 | " Some compromises had to be made to support both Python 3 and 2. |
| 60 | " We include Python 3 features, but when a definition is duplicated, |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 61 | " the last definition takes precedence. |
| 62 | " |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 63 | " - 'False', 'None', and 'True' are keywords in Python 3 but they are |
| 64 | " built-ins in 2 and will be highlighted as built-ins below. |
| 65 | " - 'exec' is a built-in in Python 3 and will be highlighted as |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 66 | " built-in below. |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 67 | " - 'nonlocal' is a keyword in Python 3 and will be highlighted. |
| 68 | " - 'print' is a built-in in Python 3 and will be highlighted as |
| 69 | " built-in below (use 'from __future__ import print_function' in 2) |
Bram Moolenaar | ca63501 | 2015-09-25 20:34:21 +0200 | [diff] [blame] | 70 | " - async and await were added in Python 3.5 and are soft keywords. |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 71 | " |
Bram Moolenaar | 6f1d9a0 | 2016-07-24 14:12:38 +0200 | [diff] [blame] | 72 | syn keyword pythonStatement False None True |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 73 | syn keyword pythonStatement as assert break continue del exec global |
| 74 | syn keyword pythonStatement lambda nonlocal pass print return with yield |
| 75 | syn keyword pythonStatement class def nextgroup=pythonFunction skipwhite |
| 76 | syn keyword pythonConditional elif else if |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 77 | syn keyword pythonRepeat for while |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 78 | syn keyword pythonOperator and in is not or |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 79 | syn keyword pythonException except finally raise try |
| 80 | syn keyword pythonInclude from import |
Bram Moolenaar | ca63501 | 2015-09-25 20:34:21 +0200 | [diff] [blame] | 81 | syn keyword pythonAsync async await |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 82 | |
Bram Moolenaar | 9c10238 | 2006-05-03 21:26:49 +0000 | [diff] [blame] | 83 | " Decorators (new in Python 2.4) |
Bram Moolenaar | e4a3bcf | 2016-08-26 19:52:37 +0200 | [diff] [blame] | 84 | " Python 3.5 introduced the use of the same symbol for matrix |
| 85 | " multiplication. We now have to exclude the symbol from being |
| 86 | " highlighted when used in that context. Hence, the check that it's |
| 87 | " preceded by empty space only (possibly in a docstring/doctest) and |
| 88 | " followed by decorator name, optional parenthesized list of arguments, |
| 89 | " and the next line with either def, class, or another decorator. |
| 90 | syn match pythonDecorator |
| 91 | \ "\%(\%(^\s*\)\%(\%(>>>\|\.\.\.\)\s\+\)\=\)\zs@\%(\s*\h\%(\w\|\.\)*\%(([^)]*)\)\=\s*\n\s*\%(\.\.\.\s\+\)\=\%(@\s*\h\|\%(def\|class\)\s\+\)\)\@=" |
| 92 | \ display nextgroup=pythonDecoratorName skipwhite |
| 93 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 94 | " A dot must be allowed because of @MyClass.myfunc decorators. |
Bram Moolenaar | e4a3bcf | 2016-08-26 19:52:37 +0200 | [diff] [blame] | 95 | " It must be preceded by a decorator symbol and on a separate line from |
| 96 | " a function/class it decorates. |
| 97 | syn match pythonDecoratorName |
| 98 | \ "\%(@\s*\)\@<=\h\%(\w\|\.\)*\%(\%(([^)]*)\)\=\s*\n\)\@=" |
| 99 | \ contained display nextgroup=pythonFunction skipnl |
| 100 | |
| 101 | " The zero-length non-grouping match of def or class before the function |
| 102 | " name is extremely important in pythonFunction. Without it, everything |
| 103 | " is interpreted as a function inside the contained environment of |
| 104 | " doctests. |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 105 | syn match pythonFunction |
Bram Moolenaar | e4a3bcf | 2016-08-26 19:52:37 +0200 | [diff] [blame] | 106 | \ "\%(\%(^\s*\)\%(\%(>>>\|\.\.\.\)\s\+\)\=\%(def\|class\)\s\+\)\@<=\h\w*" |
| 107 | \ contained |
Bram Moolenaar | 9c10238 | 2006-05-03 21:26:49 +0000 | [diff] [blame] | 108 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 109 | syn match pythonComment "#.*$" contains=pythonTodo,@Spell |
| 110 | syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained |
| 111 | |
| 112 | " Triple-quoted strings can contain doctests. |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 113 | syn region pythonString matchgroup=pythonQuotes |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 114 | \ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" |
| 115 | \ contains=pythonEscape,@Spell |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 116 | syn region pythonString matchgroup=pythonTripleQuotes |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 117 | \ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend |
| 118 | \ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 119 | syn region pythonRawString matchgroup=pythonQuotes |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 120 | \ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" |
| 121 | \ contains=@Spell |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 122 | syn region pythonRawString matchgroup=pythonTripleQuotes |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 123 | \ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend |
| 124 | \ contains=pythonSpaceError,pythonDoctest,@Spell |
| 125 | |
| 126 | syn match pythonEscape +\\[abfnrtv'"\\]+ contained |
| 127 | syn match pythonEscape "\\\o\{1,3}" contained |
| 128 | syn match pythonEscape "\\x\x\{2}" contained |
| 129 | syn match pythonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained |
| 130 | " Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/ |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 131 | syn match pythonEscape "\\N{\a\+\%(\s\a\+\)*}" contained |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 132 | syn match pythonEscape "\\$" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 133 | |
| 134 | if exists("python_highlight_all") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 135 | if exists("python_no_builtin_highlight") |
| 136 | unlet python_no_builtin_highlight |
| 137 | endif |
| 138 | if exists("python_no_doctest_code_highlight") |
| 139 | unlet python_no_doctest_code_highlight |
| 140 | endif |
| 141 | if exists("python_no_doctest_highlight") |
| 142 | unlet python_no_doctest_highlight |
| 143 | endif |
| 144 | if exists("python_no_exception_highlight") |
| 145 | unlet python_no_exception_highlight |
| 146 | endif |
| 147 | if exists("python_no_number_highlight") |
| 148 | unlet python_no_number_highlight |
| 149 | endif |
| 150 | let python_space_error_highlight = 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 151 | endif |
| 152 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 153 | " It is very important to understand all details before changing the |
| 154 | " regular expressions below or their order. |
| 155 | " The word boundaries are *not* the floating-point number boundaries |
| 156 | " because of a possible leading or trailing decimal point. |
| 157 | " The expressions below ensure that all valid number literals are |
| 158 | " highlighted, and invalid number literals are not. For example, |
| 159 | " |
| 160 | " - a decimal point in '4.' at the end of a line is highlighted, |
| 161 | " - a second dot in 1.0.0 is not highlighted, |
| 162 | " - 08 is not highlighted, |
| 163 | " - 08e0 or 08j are highlighted, |
| 164 | " |
| 165 | " and so on, as specified in the 'Python Language Reference'. |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 166 | " https://docs.python.org/2/reference/lexical_analysis.html#numeric-literals |
| 167 | " https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 168 | if !exists("python_no_number_highlight") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 169 | " numbers (including longs and complex) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 170 | syn match pythonNumber "\<0[oO]\=\o\+[Ll]\=\>" |
| 171 | syn match pythonNumber "\<0[xX]\x\+[Ll]\=\>" |
| 172 | syn match pythonNumber "\<0[bB][01]\+[Ll]\=\>" |
| 173 | syn match pythonNumber "\<\%([1-9]\d*\|0\)[Ll]\=\>" |
| 174 | syn match pythonNumber "\<\d\+[jJ]\>" |
| 175 | syn match pythonNumber "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" |
| 176 | syn match pythonNumber |
| 177 | \ "\<\d\+\.\%([eE][+-]\=\d\+\)\=[jJ]\=\%(\W\|$\)\@=" |
| 178 | syn match pythonNumber |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 179 | \ "\%(^\|\W\)\zs\d*\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 180 | endif |
| 181 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 182 | " Group the built-ins in the order in the 'Python Library Reference' for |
| 183 | " easier comparison. |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 184 | " https://docs.python.org/2/library/constants.html |
| 185 | " https://docs.python.org/3/library/constants.html |
| 186 | " http://docs.python.org/2/library/functions.html |
| 187 | " http://docs.python.org/3/library/functions.html |
| 188 | " http://docs.python.org/2/library/functions.html#non-essential-built-in-functions |
| 189 | " http://docs.python.org/3/library/functions.html#non-essential-built-in-functions |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 190 | " Python built-in functions are in alphabetical order. |
| 191 | if !exists("python_no_builtin_highlight") |
| 192 | " built-in constants |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 193 | " 'False', 'True', and 'None' are also reserved words in Python 3 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 194 | syn keyword pythonBuiltin False True None |
| 195 | syn keyword pythonBuiltin NotImplemented Ellipsis __debug__ |
| 196 | " built-in functions |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 197 | syn keyword pythonBuiltin abs all any bin bool bytearray callable chr |
| 198 | syn keyword pythonBuiltin classmethod compile complex delattr dict dir |
| 199 | syn keyword pythonBuiltin divmod enumerate eval filter float format |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 200 | syn keyword pythonBuiltin frozenset getattr globals hasattr hash |
| 201 | syn keyword pythonBuiltin help hex id input int isinstance |
| 202 | syn keyword pythonBuiltin issubclass iter len list locals map max |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 203 | syn keyword pythonBuiltin memoryview min next object oct open ord pow |
| 204 | syn keyword pythonBuiltin print property range repr reversed round set |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 205 | syn keyword pythonBuiltin setattr slice sorted staticmethod str |
| 206 | syn keyword pythonBuiltin sum super tuple type vars zip __import__ |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 207 | " Python 2 only |
| 208 | syn keyword pythonBuiltin basestring cmp execfile file |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 209 | syn keyword pythonBuiltin long raw_input reduce reload unichr |
| 210 | syn keyword pythonBuiltin unicode xrange |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 211 | " Python 3 only |
| 212 | syn keyword pythonBuiltin ascii bytes exec |
| 213 | " non-essential built-in functions; Python 2 only |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 214 | syn keyword pythonBuiltin apply buffer coerce intern |
Bram Moolenaar | 77cdfd1 | 2016-03-12 12:57:59 +0100 | [diff] [blame] | 215 | " avoid highlighting attributes as builtins |
| 216 | syn match pythonAttribute /\.\h\w*/hs=s+1 contains=ALLBUT,pythonBuiltin transparent |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 217 | endif |
| 218 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 219 | " From the 'Python Library Reference' class hierarchy at the bottom. |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 220 | " http://docs.python.org/2/library/exceptions.html |
| 221 | " http://docs.python.org/3/library/exceptions.html |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 222 | if !exists("python_no_exception_highlight") |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 223 | " builtin base exceptions (used mostly as base classes for other exceptions) |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 224 | syn keyword pythonExceptions BaseException Exception |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 225 | syn keyword pythonExceptions ArithmeticError BufferError |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 226 | syn keyword pythonExceptions LookupError |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 227 | " builtin base exceptions removed in Python 3 |
| 228 | syn keyword pythonExceptions EnvironmentError StandardError |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 229 | " builtin exceptions (actually raised) |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 230 | syn keyword pythonExceptions AssertionError AttributeError |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 231 | syn keyword pythonExceptions EOFError FloatingPointError GeneratorExit |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 232 | syn keyword pythonExceptions ImportError IndentationError |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 233 | syn keyword pythonExceptions IndexError KeyError KeyboardInterrupt |
| 234 | syn keyword pythonExceptions MemoryError NameError NotImplementedError |
| 235 | syn keyword pythonExceptions OSError OverflowError ReferenceError |
| 236 | syn keyword pythonExceptions RuntimeError StopIteration SyntaxError |
| 237 | syn keyword pythonExceptions SystemError SystemExit TabError TypeError |
| 238 | syn keyword pythonExceptions UnboundLocalError UnicodeError |
| 239 | syn keyword pythonExceptions UnicodeDecodeError UnicodeEncodeError |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 240 | syn keyword pythonExceptions UnicodeTranslateError ValueError |
| 241 | syn keyword pythonExceptions ZeroDivisionError |
| 242 | " builtin OS exceptions in Python 3 |
| 243 | syn keyword pythonExceptions BlockingIOError BrokenPipeError |
| 244 | syn keyword pythonExceptions ChildProcessError ConnectionAbortedError |
| 245 | syn keyword pythonExceptions ConnectionError ConnectionRefusedError |
| 246 | syn keyword pythonExceptions ConnectionResetError FileExistsError |
| 247 | syn keyword pythonExceptions FileNotFoundError InterruptedError |
| 248 | syn keyword pythonExceptions IsADirectoryError NotADirectoryError |
| 249 | syn keyword pythonExceptions PermissionError ProcessLookupError |
Bram Moolenaar | ca63501 | 2015-09-25 20:34:21 +0200 | [diff] [blame] | 250 | syn keyword pythonExceptions RecursionError StopAsyncIteration |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 251 | syn keyword pythonExceptions TimeoutError |
| 252 | " builtin exceptions deprecated/removed in Python 3 |
| 253 | syn keyword pythonExceptions IOError VMSError WindowsError |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 254 | " builtin warnings |
| 255 | syn keyword pythonExceptions BytesWarning DeprecationWarning FutureWarning |
| 256 | syn keyword pythonExceptions ImportWarning PendingDeprecationWarning |
| 257 | syn keyword pythonExceptions RuntimeWarning SyntaxWarning UnicodeWarning |
| 258 | syn keyword pythonExceptions UserWarning Warning |
Bram Moolenaar | f913281 | 2015-07-21 19:19:13 +0200 | [diff] [blame] | 259 | " builtin warnings in Python 3 |
| 260 | syn keyword pythonExceptions ResourceWarning |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 261 | endif |
| 262 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 263 | if exists("python_space_error_highlight") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 264 | " trailing whitespace |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 265 | syn match pythonSpaceError display excludenl "\s\+$" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 266 | " mixed tabs and spaces |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 267 | syn match pythonSpaceError display " \+\t" |
| 268 | syn match pythonSpaceError display "\t\+ " |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 269 | endif |
| 270 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 271 | " Do not spell doctests inside strings. |
| 272 | " Notice that the end of a string, either ''', or """, will end the contained |
| 273 | " doctest too. Thus, we do *not* need to have it as an end pattern. |
| 274 | if !exists("python_no_doctest_highlight") |
Bram Moolenaar | 34700a6 | 2013-03-07 13:20:54 +0100 | [diff] [blame] | 275 | if !exists("python_no_doctest_code_highlight") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 276 | syn region pythonDoctest |
| 277 | \ start="^\s*>>>\s" end="^\s*$" |
| 278 | \ contained contains=ALLBUT,pythonDoctest,@Spell |
| 279 | syn region pythonDoctestValue |
| 280 | \ start=+^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$" |
| 281 | \ contained |
| 282 | else |
| 283 | syn region pythonDoctest |
| 284 | \ start="^\s*>>>" end="^\s*$" |
| 285 | \ contained contains=@NoSpell |
| 286 | endif |
| 287 | endif |
| 288 | |
| 289 | " Sync at the beginning of class, function, or method definition. |
| 290 | syn sync match pythonSync grouphere NONE "^\s*\%(def\|class\)\s\+\h\w*\s*(" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 291 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 292 | |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 293 | " The default highlight links. Can be overridden later. |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 294 | hi def link pythonStatement Statement |
| 295 | hi def link pythonConditional Conditional |
| 296 | hi def link pythonRepeat Repeat |
| 297 | hi def link pythonOperator Operator |
| 298 | hi def link pythonException Exception |
| 299 | hi def link pythonInclude Include |
| 300 | hi def link pythonAsync Statement |
| 301 | hi def link pythonDecorator Define |
| 302 | hi def link pythonDecoratorName Function |
| 303 | hi def link pythonFunction Function |
| 304 | hi def link pythonComment Comment |
| 305 | hi def link pythonTodo Todo |
| 306 | hi def link pythonString String |
| 307 | hi def link pythonRawString String |
| 308 | hi def link pythonQuotes String |
| 309 | hi def link pythonTripleQuotes pythonQuotes |
| 310 | hi def link pythonEscape Special |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 311 | if !exists("python_no_number_highlight") |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 312 | hi def link pythonNumber Number |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 313 | endif |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 314 | if !exists("python_no_builtin_highlight") |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 315 | hi def link pythonBuiltin Function |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 316 | endif |
| 317 | if !exists("python_no_exception_highlight") |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 318 | hi def link pythonExceptions Structure |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 319 | endif |
| 320 | if exists("python_space_error_highlight") |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 321 | hi def link pythonSpaceError Error |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 322 | endif |
| 323 | if !exists("python_no_doctest_highlight") |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 324 | hi def link pythonDoctest Special |
| 325 | hi def link pythonDoctestValue Define |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 326 | endif |
| 327 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 328 | |
| 329 | let b:current_syntax = "python" |
| 330 | |
Bram Moolenaar | 0065906 | 2010-09-21 22:34:02 +0200 | [diff] [blame] | 331 | let &cpo = s:cpo_save |
| 332 | unlet s:cpo_save |
| 333 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 334 | " vim:set sw=2 sts=2 ts=8 noet: |