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

Relax q"EOS strings #20760

Open
Bolpat opened this issue Jan 23, 2025 · 2 comments
Open

Relax q"EOS strings #20760

Bolpat opened this issue Jan 23, 2025 · 2 comments

Comments

@Bolpat
Copy link
Contributor

Bolpat commented Jan 23, 2025

Currently, Identifier-delimited strings must have the closing delimiter on the first line. That looks awful in code. C# has """ strings that are either in-line or multi-line, and the multi-lines have the property that the indentation of the closing """ is subtracted from every line of the literal. D could do the same with its Identifier-delimited strings.

// current D code
void f()
{
    auto xs = q"EOS
TODO
  - propose another string literal
EOS";
}
// equivalent C# code
void F()
{
    var xs = """
    TODO
      - propose another string literal
    """;
    // or, alternatively:
    var xs = """
        TODO
          - propose another string literal
        """;
}
// proposed D code
void f()
{
    auto xs = q"EOS
    TODO
      - propose another string literal
    EOS";
}

Technically, that is a breaking change, as EOS" may occur inside the literal (just not at the beginning of a line), but probably two things are true about current D code:

  • q"EOS strings are rare.
  • The few q"EOS strings that do exist don’t have EOS anywhere in the string content, let alone EOS".

The fix is trivial: Use another identifier.

@ZILtoid1991
Copy link

I think a single q"{ ... }" is enough for 99% of applications. My updated SDL specs added this kind of string under the name "scoped string", and the parser only checks for a single }" at the end, and does not do any scope counting.

@Bolpat
Copy link
Contributor Author

Bolpat commented Feb 4, 2025

I think a single q"{ ... }" is enough for 99% of applications.

You’re missing the point. The point is about indentation.

void main()
{
	import std.stdio;
	writeln([q"{
		Hello D
	}"]);
}

This prints ["\n\t\tHello D\n\t"]. What I want is: ["\tHello D"]. (I’m using [] so writeln prints escape sequences.)

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

No branches or pull requests

2 participants