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