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