mirror of
https://github.com/neovim/neovim
synced 2025-07-15 16:51:49 +00:00
vim-patch:a24f5be: runtime(python): highlight bytes in python
- Highlight bytes literals
- Do not highlight Unicode escape sequences in bytes literals
fixes: vim/vim#14033
fixes: vim/vim#17726
closes: vim/vim#17728
a24f5be86d
Co-authored-by: Rob B <github@0x7e.net>
This commit is contained in:
committed by
Christian Clason
parent
3eb597c999
commit
d4c8e8df1c
@ -1,9 +1,10 @@
|
|||||||
" Vim syntax file
|
" Vim syntax file
|
||||||
" Language: Python
|
" Language: Python
|
||||||
" Maintainer: Zvezdan Petkovic <zpetkovic@acm.org>
|
" Maintainer: Zvezdan Petkovic <zpetkovic@acm.org>
|
||||||
" Last Change: 2023 Feb 28
|
" Last Change: 2025 Jul 14
|
||||||
" 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.
|
||||||
"
|
"
|
||||||
@ -144,24 +145,48 @@ 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=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
|
||||||
\ contains=pythonEscape,@Spell
|
\ contains=pythonEscape,pythonUnicodeEscape,@Spell
|
||||||
syn region pythonString matchgroup=pythonTripleQuotes
|
syn region pythonString matchgroup=pythonTripleQuotes
|
||||||
\ start=+[uU]\=\z('''\|"""\)+ skip=+\\["']+ end="\z1" keepend
|
\ start=+[uU]\=\z('''\|"""\)+ skip=+\\["']+ end="\z1" keepend
|
||||||
\ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
|
\ contains=pythonEscape,pythonUnicodeEscape,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
|
||||||
|
|
||||||
|
" 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 +\\[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/
|
||||||
" The specification: https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-4/#G135165
|
" 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 "\\$"
|
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
|
||||||
@ -313,9 +338,12 @@ hi def link pythonComment Comment
|
|||||||
hi def link pythonTodo Todo
|
hi def link pythonTodo Todo
|
||||||
hi def link pythonString String
|
hi def link pythonString String
|
||||||
hi def link pythonRawString String
|
hi def link pythonRawString String
|
||||||
|
hi def link pythonBytes String
|
||||||
|
hi def link pythonRawBytes 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
|
||||||
|
Reference in New Issue
Block a user