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