Skip to content

Commit c661c01

Browse files
committedDec 2, 2020
Merge branch 'fstring'
2 parents c1c5baf + 082a78a commit c661c01

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed
 

‎syntax/python.vim

+3-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ else
103103
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunction skipwhite
104104
syn match pythonStatement '\<async\s\+with\>'
105105
syn match pythonStatement '\<async\s\+for\>'
106-
syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType
106+
syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonFString,pythonRawString,pythonRawFString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType
107107
endif
108108

109109

@@ -264,8 +264,8 @@ if s:Enabled('g:python_highlight_string_format')
264264
syn match pythonStrFormat '{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
265265
else
266266
syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString
267-
syn region pythonStrInterpRegion start="{"he=e+1,rs=e+1 end="\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}"hs=s-1,re=s-1 extend contained containedin=pythonFString,pythonRawFString contains=pythonStrInterpRegion,@pythonExpression
268-
syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString,pythonFString,pythonRawFString
267+
syn region pythonStrInterpRegion matchgroup=pythonStrFormat start="{" end="\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" extend contained containedin=pythonFString,pythonRawFString contains=pythonStrInterpRegion,@pythonExpression
268+
syn match pythonStrFormat "{{\|}}" contained containedin=pythonFString,pythonRawFString
269269
endif
270270
endif
271271

@@ -471,7 +471,6 @@ if v:version >= 508 || !exists('did_python_syn_inits')
471471
HiLink pythonBytesEscapeError Error
472472
HiLink pythonFString String
473473
HiLink pythonRawFString String
474-
HiLink pythonStrInterpRegion Special
475474
endif
476475

477476
HiLink pythonStrFormatting Special

‎tests/test.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,11 @@ async def Test
244244
f"{var}...{arr[123]} normal {var['{'] // 0xff} \"xzcb\" 'xzcb' {var['}'] + 1} text"
245245
f"{expr1 if True or False else expr2} {None} wow {','.join(c.lower() for c in 'asdf')}"
246246
f"hello {expr:.2f} yes {(lambda: 0b1)():#03x} lol {var!r}"
247-
f'brackets: {{ 1 + 2 }} and {{{{ 3 + 4 }}}}'
247+
f'brackets: {{{ 1 + 2 }}} and {{{{ 3 + 4 }}}}'
248248
fr'this {that}'
249+
f"{f'{1+1}'}"
250+
'{{ }}'
251+
f"{"{test}"}" # FIXME: syntax error that should not be highlighted
249252

250253
# Doctests.
251254

0 commit comments

Comments
 (0)
Please sign in to comment.