Add python f-string and string-prefix highlight
close #14033
Following up on comments in https://github.com/vim/vim/issues/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.
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