mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
runtime(python): add syntax support inside f-strings
fixes: #14033 closes: #17962 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
9fd1a657d2
commit
d2b28ddfc2
@@ -1,7 +1,7 @@
|
||||
" Vim syntax file
|
||||
" Language: Python
|
||||
" Maintainer: Zvezdan Petkovic <zpetkovic@acm.org>
|
||||
" Last Change: 2025 Aug 23
|
||||
" Last Change: 2025 Sep 05
|
||||
" Credits: Neil Schemenauer <nas@python.ca>
|
||||
" Dmitry Vasiliev
|
||||
" Rob B
|
||||
@@ -218,21 +218,24 @@ syn region pythonRawBytes
|
||||
|
||||
" F-string replacement fields
|
||||
"
|
||||
" - Matched parentheses, brackets and braces are ignored
|
||||
" - A bare # is ignored to end of line
|
||||
" - A bare = (surrounded by optional whitespace) enables debugging
|
||||
" - A bare ! prefixes a conversion field
|
||||
" - Matched parentheses, brackets and braces are skipped
|
||||
" - A bare = (followed by optional whitespace) enables debugging
|
||||
" - A bare ! prefixes a conversion field (followed by optional whitespace)
|
||||
" - A bare : begins a format specification
|
||||
" - Matched braces inside a format specification are ignored
|
||||
" - Matched braces inside a format specification are skipped
|
||||
"
|
||||
syn region pythonFStringField
|
||||
\ matchgroup=pythonFStringDelimiter
|
||||
\ start=/{/
|
||||
\ skip=/([^)]*)\|\[[^]]*]\|{[^}]*}\|#.*$/
|
||||
\ end=/\%(\s*=\s*\)\=\%(!\a\)\=\%(:\%({[^}]*}\|[^}]*\)\+\)\=}/
|
||||
\ end=/\%(=\s*\)\=\%(!\a\s*\)\=\%(:\%({\_[^}]*}\|[^{}]*\)\+\)\=}/
|
||||
\ contained
|
||||
" Doubled braces and Unicode escapes are not replacement fields
|
||||
syn match pythonFStringSkip /{{\|\\N{/ transparent contained contains=NONE
|
||||
\ contains=ALLBUT,pythonFStringField,pythonClass,pythonFunction,pythonDoctest,pythonDoctestValue,@Spell
|
||||
syn match pythonFStringFieldSkip /(\_[^()]*)\|\[\_[^][]*]\|{\_[^{}]*}/
|
||||
\ contained
|
||||
\ contains=ALLBUT,pythonFStringField,pythonClass,pythonFunction,pythonDoctest,pythonDoctestValue,@Spell
|
||||
|
||||
" Doubled braces are not replacement fields
|
||||
syn match pythonFStringSkip /{{/ transparent contained contains=NONE
|
||||
|
||||
syn match pythonEscape +\\[abfnrtv'"\\]+ contained
|
||||
syn match pythonEscape "\\\o\{1,3}" contained
|
||||
|
Reference in New Issue
Block a user