Skip to content

Incorrect highlighting of nested braces in format strings. #12

Closed

Description

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

This is illegal nesting of braces for a format string.

Activity

  1. vpetrovykh commented on Oct 20, 2015

    @vpetrovykh
    ContributorAuthor

    see also this issue

  2. vpetrovykh commented on Oct 21, 2015

    @vpetrovykh
    ContributorAuthor

    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.

  3. vpetrovykh commented on Oct 21, 2015

    @vpetrovykh
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions