mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
runtime(python): highlight bytes in python
- Highlight bytes literals - Do not highlight Unicode escape sequences in bytes literals fixes: #14033 fixes: #17726 closes: #17728 Signed-off-by: Rob B <github@0x7e.net> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
baa781a4c3
commit
a24f5be86d
@@ -1,9 +1,10 @@
|
||||
" Vim syntax file
|
||||
" Language: Python
|
||||
" Maintainer: Zvezdan Petkovic <zpetkovic@acm.org>
|
||||
" Last Change: 2023 Feb 28
|
||||
" Last Change: 2025 Jul 14
|
||||
" Credits: Neil Schemenauer <nas@python.ca>
|
||||
" Dmitry Vasiliev
|
||||
" Rob B
|
||||
"
|
||||
" This version is a major rewrite by Zvezdan Petkovic.
|
||||
"
|
||||
@@ -144,24 +145,48 @@ 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"
|
||||
\ contains=pythonEscape,@Spell
|
||||
\ contains=pythonEscape,pythonUnicodeEscape,@Spell
|
||||
syn region pythonString matchgroup=pythonTripleQuotes
|
||||
\ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
|
||||
\ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
|
||||
\ contains=pythonEscape,pythonUnicodeEscape,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
|
||||
|
||||
" Bytes
|
||||
syn region pythonBytes
|
||||
\ matchgroup=pythonQuotes
|
||||
\ start=+\cB\z(['"]\)+
|
||||
\ end="\z1"
|
||||
\ skip="\\\\\|\\\z1"
|
||||
\ contains=pythonEscape
|
||||
syn region pythonBytes
|
||||
\ matchgroup=pythonTripleQuotes
|
||||
\ start=+\cB\z('''\|"""\)+
|
||||
\ end="\z1"
|
||||
\ keepend
|
||||
\ contains=pythonEscape
|
||||
syn region pythonRawBytes
|
||||
\ matchgroup=pythonQuotes
|
||||
\ start=+\c\%(BR\|RB\)\z(['"]\)+
|
||||
\ end="\z1"
|
||||
\ skip="\\\\\|\\\z1"
|
||||
syn region pythonRawBytes
|
||||
\ matchgroup=pythonTripleQuotes
|
||||
\ start=+\c\%(BR\|RB\)\z('''\|"""\)+
|
||||
\ end="\z1"
|
||||
\ keepend
|
||||
|
||||
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/
|
||||
" The specification: https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-4/#G135165
|
||||
syn match pythonEscape "\\N{\a\+\%(\%(\s\a\+[[:alnum:]]*\)\|\%(-[[:alnum:]]\+\)\)*}" contained
|
||||
syn match pythonUnicodeEscape "\\N{\a\+\%(\%(\s\a\+[[:alnum:]]*\)\|\%(-[[:alnum:]]\+\)\)*}" contained
|
||||
syn match pythonEscape "\\$"
|
||||
|
||||
" It is very important to understand all details before changing the
|
||||
@@ -313,9 +338,12 @@ hi def link pythonComment Comment
|
||||
hi def link pythonTodo Todo
|
||||
hi def link pythonString String
|
||||
hi def link pythonRawString String
|
||||
hi def link pythonBytes String
|
||||
hi def link pythonRawBytes 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
|
||||
|
Reference in New Issue
Block a user