Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect highlighting of nested braces in format strings. #12

Closed
vpetrovykh opened this issue Oct 20, 2015 · 3 comments
Closed

Incorrect highlighting of nested braces in format strings. #12

vpetrovykh opened this issue Oct 20, 2015 · 3 comments
Labels

Comments

@vpetrovykh
Copy link
Member

R'\frac{m_{j \rightarrow i}(\mathrm{good})}'

This is illegal nesting of braces for a format string.

@vpetrovykh vpetrovykh added the bug label Oct 20, 2015
@vpetrovykh
Copy link
Member Author

see also this issue

@vpetrovykh
Copy link
Member Author

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.

@vpetrovykh
Copy link
Member Author

Fixed in v0.4.28 (relevant commit b9aa8b0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant