vim-patch:baa781a: runtime(python2): highlight unicode strings in python2

fixes: vim/vim#14033
fixes: vim/vim#17726
closes: vim/vim#17729

baa781a4c3

Co-authored-by: Rob B <github@0x7e.net>
This commit is contained in:
Christian Clason
2025-07-14 23:04:17 +02:00
committed by Christian Clason
parent 73987a4301
commit 3eb597c999

View File

@ -2,8 +2,10 @@
" Language: Python 2
" Maintainer: Zvezdan Petkovic <zpetkovic@acm.org>
" Last Change: 2016 Oct 29
" 2025 Jul 14 by Vim project: highlight unicode strings
" Credits: Neil Schemenauer <nas@python.ca>
" Dmitry Vasiliev
" Rob B
"
" This version is a major rewrite by Zvezdan Petkovic.
"
@ -141,24 +143,53 @@ syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained
" Triple-quoted strings can contain doctests.
syn region pythonString matchgroup=pythonQuotes
\ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
\ start=+\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
\ contains=pythonEscape,@Spell
syn region pythonString matchgroup=pythonTripleQuotes
\ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
\ start=+\z('''\|"""\)+ end="\z1" keepend
\ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
syn region pythonRawString matchgroup=pythonQuotes
\ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
\ start=+[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
\ contains=@Spell
syn region pythonRawString matchgroup=pythonTripleQuotes
\ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
\ start=+[rR]\z('''\|"""\)+ end="\z1" keepend
\ contains=pythonSpaceError,pythonDoctest,@Spell
" Unicode strings
syn region pythonString
\ matchgroup=pythonQuotes
\ start=+[uU]\z(['"]\)+
\ end="\z1"
\ skip="\\\\\|\\\z1"
\ contains=pythonEscape,pythonUnicodeEscape,@Spell
syn region pythonString
\ matchgroup=pythonTripleQuotes
\ start=+[uU]\z('''\|"""\)+
\ end="\z1"
\ keepend
\ contains=pythonEscape,pythonUnicodeEscape,pythonSpaceError,pythonDoctest,@Spell
" Raw Unicode strings recognize Unicode escape sequences
" https://docs.python.org/2.7/reference/lexical_analysis.html#string-literals
syn region pythonRawString
\ matchgroup=pythonQuotes
\ start=+[uU][rR]\z(['"]\)+
\ end="\z1"
\ skip="\\\\\|\\\z1"
\ contains=pythonUnicodeEscape,@Spell
syn region pythonRawString
\ matchgroup=pythonTripleQuotes
\ start=+[uU][rR]\z('''\|"""\)+
\ end="\z1"
\ keepend
\ contains=pythonUnicodeEscape,pythonSpaceError,pythonDoctest,@Spell
syn match pythonEscape +\\[abfnrtv'"\\]+ contained
syn match pythonEscape "\\\o\{1,3}" contained
syn match pythonEscape "\\x\x\{2}" contained
syn match pythonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained
syn match pythonUnicodeEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained
" Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/
syn match pythonEscape "\\N{\a\+\%(\s\a\+\)*}" contained
syn match pythonUnicodeEscape "\\N{\a\+\%(\s\a\+\)*}" contained
syn match pythonEscape "\\$"
" It is very important to understand all details before changing the
@ -320,6 +351,7 @@ hi def link pythonRawString String
hi def link pythonQuotes String
hi def link pythonTripleQuotes pythonQuotes
hi def link pythonEscape Special
hi def link pythonUnicodeEscape pythonEscape
if !exists("python_no_number_highlight")
hi def link pythonNumber Number
endif