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 " Language: Python 2
" Maintainer: Zvezdan Petkovic <zpetkovic@acm.org> " Maintainer: Zvezdan Petkovic <zpetkovic@acm.org>
" Last Change: 2016 Oct 29 " Last Change: 2016 Oct 29
" 2025 Jul 14 by Vim project: highlight unicode strings
" Credits: Neil Schemenauer <nas@python.ca> " Credits: Neil Schemenauer <nas@python.ca>
" Dmitry Vasiliev " Dmitry Vasiliev
" Rob B
" "
" This version is a major rewrite by Zvezdan Petkovic. " 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. " Triple-quoted strings can contain doctests.
syn region pythonString matchgroup=pythonQuotes syn region pythonString matchgroup=pythonQuotes
\ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" \ start=+\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
\ contains=pythonEscape,@Spell \ contains=pythonEscape,@Spell
syn region pythonString matchgroup=pythonTripleQuotes syn region pythonString matchgroup=pythonTripleQuotes
\ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend \ start=+\z('''\|"""\)+ end="\z1" keepend
\ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell \ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
syn region pythonRawString matchgroup=pythonQuotes syn region pythonRawString matchgroup=pythonQuotes
\ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" \ start=+[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
\ contains=@Spell \ contains=@Spell
syn region pythonRawString matchgroup=pythonTripleQuotes syn region pythonRawString matchgroup=pythonTripleQuotes
\ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend \ start=+[rR]\z('''\|"""\)+ end="\z1" keepend
\ contains=pythonSpaceError,pythonDoctest,@Spell \ 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 +\\[abfnrtv'"\\]+ contained
syn match pythonEscape "\\\o\{1,3}" contained syn match pythonEscape "\\\o\{1,3}" contained
syn match pythonEscape "\\x\x\{2}" 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/ " 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 "\\$" syn match pythonEscape "\\$"
" It is very important to understand all details before changing the " 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 pythonQuotes String
hi def link pythonTripleQuotes pythonQuotes hi def link pythonTripleQuotes pythonQuotes
hi def link pythonEscape Special hi def link pythonEscape Special
hi def link pythonUnicodeEscape pythonEscape
if !exists("python_no_number_highlight") if !exists("python_no_number_highlight")
hi def link pythonNumber Number hi def link pythonNumber Number
endif endif