close #14033
https://github.com/vim/vim/pull/14048
(1 file)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Following up on comments in #14033
You can add the
pythonFStringValuegroup to its owncontainslist to simplify matching these nested replacement fields. Then the end pattern can probably be reduced to a closing brace.I cannot add it to its own contains list, it should only take effect on the right side of the colon, and the expression needs to be highlighted on the left side
I don't know, but I suspect that the likelihood of collection literal matches in the expression is much lower than computed format specs. I found some of the latter and none of the former in a quick search. Simply containing it recursively would probably only result in highlighted braces in the expression, in the worst case, which might be worth living with.
I just skimmed the PEP (not a Python user, take with a grain of salt) and it seems that this could be matched properly with a bit of effort.
You could create a series of regions contained in pythonFStringValue for the expression, conversion and format specification and have the format specification contain pythonFStringValue. It would probably be simplest to anchor the expression region to the start of the pythonFStringValue region with a look-behind and match them sequentially with :syn-nextgroup.
Unfortunately, the syntax file doesn't match other brace delimited syntax but those could be added and mixed with :syn-skip patterns to ignore parenthesised ! and :.
I'm not suggesting that this should be done, just that it's possible.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Following up on comments in #14033
You can add the
pythonFStringValuegroup to its owncontainslist to simplify matching these nested replacement fields. Then the end pattern can probably be reduced to a closing brace.I cannot add it to its own contains list, it should only take effect on the right side of the colon, and the expression needs to be highlighted on the left side
I don't know, but I suspect that the likelihood of collection literal matches in the expression is much lower than computed format specs. I found some of the latter and none of the former in a quick search. Simply containing it recursively would probably only result in highlighted braces in the expression, in the worst case, which might be worth living with.
I just skimmed the PEP (not a Python user, take with a grain of salt) and it seems that this could be matched properly with a bit of effort.
You could create a series of regions contained in
pythonFStringValuefor the expression, conversion and format specification and have the format specification containpythonFStringValue. It would probably be simplest to anchor the expression region to the start of thepythonFStringValueregion with a look-behind and match them sequentially with:syn-nextgroup.Unfortunately, the syntax file doesn't match other brace delimited syntax but those could be added and mixed with
:syn-skippatterns to ignore parenthesised!and:.I'm not suggesting that this should be done, just that it's possible.
I don't want incorrect highlighting like f'{exec("if 1:{}")}', and if I want to contains it myself, I won't be able to use TOP because it can only be excluded
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@dkearns requested changes on this pull request.
I don't want incorrect highlighting like
f'{exec("if 1:{}")}', and if I want to contains it myself, I won't be able to use TOP because it can only be excluded
None of my suggestions would highlight that example incorrectly. The exec argument would just be matched as a plain string.
TOP is just a convenience. It would be nice if the contains syntax was a bit more expressive to allow groups to be added as well but you can define a new cluster including only the required expression groups. Technically, of course, TOP matches too much anyway.
>
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
" Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/
syn match pythonEscape "\\N{\a\+\%(\s\a\+\)*}" contained
-syn match pythonEscape "\\$"
+syn match pythonEscape "\\\r\=$"
+
+syn region pythonFStringValue matchgroup=pythonFStringBrace
+ \ start=+{+ end=+=\=\%(![rsa]\)\=\%(:[^{}]*\%({[^{}]*\%({[^{}]*}[^{}]*\)*}[^{}]*\)*\)\=}+ contains=TOP contained excludenl
excludenl shouldn't be needed here as the pattern doesn't match EOL.
> hi def link pythonQuotes String hi def link pythonTripleQuotes pythonQuotes hi def link pythonEscape Special +hi def link pythonFStringEscapedBrace Special +hi def link pythonFStringValue Normal
This isn't usually specified as it is the default if no highlight group is linked but does no harm.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
closing this one and awaiting a new patch from the maintainer.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Closed #14048.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()