Thread overview
Official annotations/attributes for strings for commonly used languages.
March 03

Hey, recently I posted a suggestion (DIP) for adding indentation-aware multi-line strings to the D language, but another idea has also occurred to me a few times, and I'll share it in this separate thread to keep things clean.

While it is possible to use D's string delimiting syntax to mark raw ("WYSIWYG") strings as being different types of strings implicitly, it seems like having official attributes for strings of common programming languages would increase the chances of tighter integration of syntax highlighting for other programming languages within strings.

Thus, instead of something like:

string s = q"HTML
<ul>
  <li>Item 1</li>
</ul>
HTML";

... perhaps official attributes would be better to express intent unambiguously, like so:

string s = @lang(HTML) `
<ul>
  <li>Item 1</li>
</ul>
`;

This would increase the odds of this approach becoming effective eventually in 3rd party software.

The problem with using special delimited strings for this is that there is no actual unambiguous intent to actually use the string as containing that language from the standpoint of 3rd party tools (it could just be a coincidence), whereas an official attribute that can be filled with the official commonly used language in use would be less ambiguous.

Meanwhile, users could still use the special delimited raw strings for uncommon languages or for setting up syntax scanning for languages that they themselves have made such as markup for their own data files.

Admittedly, 3rd party tooling even just for D itself is already not the best for things like IDE features and syntax, but that is no reason to not do this. Anything that helps the prospects is worth doing and things should be done on principle.

This idea is not that important to me, but I just wanted to put it out there anyway.

April 14

On Monday, 3 March 2025 at 21:03:52 UTC, WraithGlade wrote:

>

Hey, recently I posted a suggestion (DIP) for adding indentation-aware multi-line strings to the D language, but another idea has also occurred to me a few times, and I'll share it in this separate thread to keep things clean.

While it is possible to use D's string delimiting syntax to mark raw ("WYSIWYG") strings as being different types of strings implicitly, it seems like having official attributes for strings of common programming languages would increase the chances of tighter integration of syntax highlighting for other programming languages within strings.

Thus, instead of something like:

string s = q"HTML
<ul>
  <li>Item 1</li>
</ul>
HTML";

... perhaps official attributes would be better to express intent unambiguously, like so:

string s = @lang(HTML) `
<ul>
  <li>Item 1</li>
</ul>
`;

This would increase the odds of this approach becoming effective eventually in 3rd party software.

The problem with using special delimited strings for this is that there is no actual unambiguous intent to actually use the string as containing that language from the standpoint of 3rd party tools (it could just be a coincidence), whereas an official attribute that can be filled with the official commonly used language in use would be less ambiguous.

Meanwhile, users could still use the special delimited raw strings for uncommon languages or for setting up syntax scanning for languages that they themselves have made such as markup for their own data files.

Admittedly, 3rd party tooling even just for D itself is already not the best for things like IDE features and syntax, but that is no reason to not do this. Anything that helps the prospects is worth doing and things should be done on principle.

This idea is not that important to me, but I just wanted to put it out there anyway.

I guess you could probably write a library that has functions enusreValidHtml etc. that you can call on literals and they check them.

If you want syntax highlighting, D isn’t vaguely popular enough for editors to care styling string literals in the syntax of another language. If you really want that, you can use import("filename"), which for larger things, is actually preferable.

It’s not a bad idea, it just doesn’t really suit D.

April 21

On Monday, 3 March 2025 at 21:03:52 UTC, WraithGlade wrote:

>

Hey, recently I posted a suggestion (DIP) for adding indentation-aware multi-line strings to the D language, but another idea has also occurred to me a few times, and I'll share it in this separate thread to keep things clean.

[...]

This would require editor/IDE support to hightlight properly anyway, at which point I would write the code for that support to automatically recognise such strings. I don't see the advantage of it being a language feature.