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

Implement format strings. #209

Open
ta0kira opened this issue Jan 7, 2024 · 1 comment
Open

Implement format strings. #209

ta0kira opened this issue Jan 7, 2024 · 1 comment
Labels
base language Features of the language itself enhancement New feature or request

Comments

@ta0kira
Copy link
Owner

ta0kira commented Jan 7, 2024

For example, Python has f"foo is: {foo}". Something like this would be easy to implement; it could just be translated into a String.builder() call. I think the biggest decision would be what syntax to use.

@ta0kira ta0kira added enhancement New feature or request base language Features of the language itself labels Jan 7, 2024
@ta0kira
Copy link
Owner Author

ta0kira commented Jan 14, 2024

Some requirements:

  1. Any expression should be allowed within a substitution block. This means that symmetric delimiters for substitution blocks that can also be used in expressions (e.g., `, |) must not be used.
  2. The open delimiter for a substitution block should be escapable within the string, but should also be uncommon in strings. No need to make it multi-character (e.g., #{foo} in Ruby) if the start can just be escaped if needed.
  3. Indicating a format string by prefixing the opening " should also be usable for raw strings later on if added, and shouldn't seem "weird" given other uses of the prefix. For example, probably not \"..." or @"...".

Some possibilities:

  1. $"foo is: {foo}", $"Bar is: { Bar{ 123 } }"
  2. #"foo is: {foo}", #"Bar is: { Bar{ 123 } }"
  3. %"foo is: {foo}", %"Bar is: { Bar{ 123 } }"

% might actually be the best option, since it's used in C format strings, and it isn't already being parsed as a unary operator. Note that %"foo is: %{foo}" might be confusing though, because it seems like %{foo} could refer to a param passed to the formatter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
base language Features of the language itself enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant