You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect highlighting of nested braces in format strings. #12
Upon some reflection we've decided to stop highlighting format syntax that seems too unusual. According to the spec R"{(%d[ ]:X>+10d}".format(**{'(%d':{' ': 42}}) is actually legal and we originally highlighted it as such. Realistically, this is a truly obscure use case and most likely seeing a similar string indicates a mistake or a directive from some other language. So we've decided that in the spirit of making the highlighter helpful to the developer we should only highlight format syntax that uses identifier or index to refer to a format argument. On the other hand, once we encounter an invalid (e.g. R'\frac{m_{j \rightarrow i}(\mathrm{good})}') format syntax within curly braces, we stop treating any further curly braces in that same string as special.
So rule of thumb is that for strings that are actually using legal format syntax, the syntax is highlighted. For strings that seem to be using braces to do something else (producing TeX or maybe CSS strings), the highlighter tries not to get in the way. It's worth noting that %-style special formatting is highlighted in both of these cases. The motivation is that it is more likely that when .format is not safe to use, a developer would want to specifically use % style formatting instead.
Activity
vpetrovykh commentedon Oct 20, 2015
see also this issue
vpetrovykh commentedon Oct 21, 2015
Upon some reflection we've decided to stop highlighting format syntax that seems too unusual. According to the spec
R"{(%d[ ]:X>+10d}".format(**{'(%d':{' ': 42}})is actually legal and we originally highlighted it as such. Realistically, this is a truly obscure use case and most likely seeing a similar string indicates a mistake or a directive from some other language. So we've decided that in the spirit of making the highlighter helpful to the developer we should only highlight format syntax that uses identifier or index to refer to a format argument. On the other hand, once we encounter an invalid (e.g.R'\frac{m_{j \rightarrow i}(\mathrm{good})}') format syntax within curly braces, we stop treating any further curly braces in that same string as special.So rule of thumb is that for strings that are actually using legal format syntax, the syntax is highlighted. For strings that seem to be using braces to do something else (producing TeX or maybe CSS strings), the highlighter tries not to get in the way. It's worth noting that
%-style special formatting is highlighted in both of these cases. The motivation is that it is more likely that when.formatis not safe to use, a developer would want to specifically use%style formatting instead.vpetrovykh commentedon Oct 21, 2015
Fixed in v0.4.28 (relevant commit b9aa8b0).