|
1 | 1 | " Vim syntax file |
2 | 2 | " Language: Python |
3 | 3 | " Maintainer: Zvezdan Petkovic <zpetkovic@acm.org> |
4 | | -" Last Change: 2023 Feb 28 |
| 4 | +" Last Change: 2025 Jul 14 |
5 | 5 | " Credits: Neil Schemenauer <nas@python.ca> |
6 | 6 | " Dmitry Vasiliev |
| 7 | +" Rob B |
7 | 8 | " |
8 | 9 | " This version is a major rewrite by Zvezdan Petkovic. |
9 | 10 | " |
@@ -144,24 +145,48 @@ syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained |
144 | 145 | " Triple-quoted strings can contain doctests. |
145 | 146 | syn region pythonString matchgroup=pythonQuotes |
146 | 147 | \ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" |
147 | | - \ contains=pythonEscape,@Spell |
| 148 | + \ contains=pythonEscape,pythonUnicodeEscape,@Spell |
148 | 149 | syn region pythonString matchgroup=pythonTripleQuotes |
149 | 150 | \ start=+[uU]\=\z('''\|"""\)+ skip=+\\["']+ end="\z1" keepend |
150 | | - \ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell |
| 151 | + \ contains=pythonEscape,pythonUnicodeEscape,pythonSpaceError,pythonDoctest,@Spell |
151 | 152 | syn region pythonRawString matchgroup=pythonQuotes |
152 | | - \ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" |
| 153 | + \ start=+[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" |
153 | 154 | \ contains=@Spell |
154 | 155 | syn region pythonRawString matchgroup=pythonTripleQuotes |
155 | | - \ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend |
| 156 | + \ start=+[rR]\z('''\|"""\)+ end="\z1" keepend |
156 | 157 | \ contains=pythonSpaceError,pythonDoctest,@Spell |
157 | 158 |
|
| 159 | +" Bytes |
| 160 | +syn region pythonBytes |
| 161 | + \ matchgroup=pythonQuotes |
| 162 | + \ start=+\cB\z(['"]\)+ |
| 163 | + \ end="\z1" |
| 164 | + \ skip="\\\\\|\\\z1" |
| 165 | + \ contains=pythonEscape |
| 166 | +syn region pythonBytes |
| 167 | + \ matchgroup=pythonTripleQuotes |
| 168 | + \ start=+\cB\z('''\|"""\)+ |
| 169 | + \ end="\z1" |
| 170 | + \ keepend |
| 171 | + \ contains=pythonEscape |
| 172 | +syn region pythonRawBytes |
| 173 | + \ matchgroup=pythonQuotes |
| 174 | + \ start=+\c\%(BR\|RB\)\z(['"]\)+ |
| 175 | + \ end="\z1" |
| 176 | + \ skip="\\\\\|\\\z1" |
| 177 | +syn region pythonRawBytes |
| 178 | + \ matchgroup=pythonTripleQuotes |
| 179 | + \ start=+\c\%(BR\|RB\)\z('''\|"""\)+ |
| 180 | + \ end="\z1" |
| 181 | + \ keepend |
| 182 | + |
158 | 183 | syn match pythonEscape +\\[abfnrtv'"\\]+ contained |
159 | 184 | syn match pythonEscape "\\\o\{1,3}" contained |
160 | 185 | syn match pythonEscape "\\x\x\{2}" contained |
161 | | -syn match pythonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained |
| 186 | +syn match pythonUnicodeEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained |
162 | 187 | " Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/ |
163 | 188 | " The specification: https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-4/#G135165 |
164 | | -syn match pythonEscape "\\N{\a\+\%(\%(\s\a\+[[:alnum:]]*\)\|\%(-[[:alnum:]]\+\)\)*}" contained |
| 189 | +syn match pythonUnicodeEscape "\\N{\a\+\%(\%(\s\a\+[[:alnum:]]*\)\|\%(-[[:alnum:]]\+\)\)*}" contained |
165 | 190 | syn match pythonEscape "\\$" |
166 | 191 |
|
167 | 192 | " It is very important to understand all details before changing the |
@@ -313,9 +338,12 @@ hi def link pythonComment Comment |
313 | 338 | hi def link pythonTodo Todo |
314 | 339 | hi def link pythonString String |
315 | 340 | hi def link pythonRawString String |
| 341 | +hi def link pythonBytes String |
| 342 | +hi def link pythonRawBytes String |
316 | 343 | hi def link pythonQuotes String |
317 | 344 | hi def link pythonTripleQuotes pythonQuotes |
318 | 345 | hi def link pythonEscape Special |
| 346 | +hi def link pythonUnicodeEscape pythonEscape |
319 | 347 | if !exists("python_no_number_highlight") |
320 | 348 | hi def link pythonNumber Number |
321 | 349 | endif |
|
0 commit comments