Skip to content

Limits on expression contents. #3

Description

@BengtGustafsson

As has been shown in extract_fx it is possible to parse expression-fields to figure out which } or : is actually ending them. A few edge cases remain, but could be solved by small changes in other parts of the library:

  • Using the comma operator in expressions. We can't forbid it at preprocessing time or MyTpl<A, B> would not work...
  • format-specs starting with colon, which today has to be written as :: for range formats if you want to specify the element format. This has not been standardized yet.

Even with this proof of concept for not having to limit expression contents there remains the question if this is too much to ask of preprocessors and tools such as static analyzers. The implementation in extract_fx adds roughly 200 lines of C++ to a preprocessor implementation and handles all known quirks of non-erroneous expressions.

Regardless of which limitations are placed on expression-fields they have to be thoroughly specified to avoid compiler divergence, which could lead to portability problems. This specification work becomes easier with less limitations, and so does teaching the feature.

In Python, from which f-literals are modeled (although they are available in many languages) PEP-701 was just implemented in version 3.12 allowing most all of Python expressions in expression-fields. Previously there were limitations on nested string literals, line breaks and comments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions