-
|
It's time to start thinking about the next v0.2 spec. A lot of feedback came for MAML. And the main criticism Initially I declined Zig-style multiline strings, and decided to use Current problems with multiline strings: We can't include another tripple quotes Indentation in deeply nested code makes it more difficult to read. MAML uses double quotes for strings with escapes How do Zig-multiline strings look like? const hello_world_in_c =
\\#include <stdio.h>
\\
\\int main(int argc, char **argv) {
\\ printf("hello world\n");
\\ return 0;
\\}
;Multiline strings in Zig are essentially comments. They solve the problem of escaping and indentation. What problems do Zig-style multiline strings have? Mixing comments and multiline-strings. But this is fixable if MAML does NOT allow comments inside multiline strings. Another point is often brought up is space after In markup language, any character (beside I'm proposing to adopt Zig-style multiline strings for MAML. But with a different character Backtick character is easy to type; it doesn't require a space after; it is visually light and easy to read. Alternatives considered:
Overall I think Raw strings with Downside: backticks are usually used as strings (i.e., expected closing backtick), this could lead to confusion, No closing backtick is needed, but if a backtick is added, it will become part of the string. So I propose one of the following scenarios:
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 7 replies
-
|
From a user standpoint, I'm not typically a fan of prefixed multi-line strings as I like that I can copy/paste content to or from non-prefixed multi-line strings and not have to deal with cleaning up or adding the prefix (though IDEs can help with this to some extent). That said, the prefix definitely helps with both nicer formatting and unambiguous indentation of the string contents My main concern with prefix-based multi-line strings is how they interact with arrays: All it takes is a misplaced newline to break a multi-line string into multiple array elements. Another issue with this approach as a replacement for the current raw-string implementation is that prefixed multi-line comments can't be used inline. The following example would not be possible: It would have to be written either using a quoted string with escaped backslashes or like this: Maybe not a deal-breaker, but the fact that prefixed multi-line strings can't be used inline is something to consider.
In my experience, I've only used
Harder to type than you're suggesting.
What's From my perspective, this proposal is likely to add more challenges than it solves. |
Beta Was this translation helpful? Give feedback.
-
|
I'm also not a fan of the prefix notation, as this makes it more difficult to copy/paste between different config formats. Related, if a tool is needed to ease editing, I think this negates the purpose of a format that is easy for humans to edit. I have a couple of ideas to think about. Have you considered Elixir's sigil syntax? It uses a tilde followed by a single character and then a delimiter. So a an inline string could be: ~s(some \nsdata\here\n) and an multi-line string could be: This would allow users to change the delimiter based on the type of string data they are embedding. For example, you could use triple-backticks for Python code, and triple-quotes if you are embedding a markdown fenced code block. |
Beta Was this translation helpful? Give feedback.
-
|
@antonmedv In a previous thread, you had mentioned potentially allowing |
Beta Was this translation helpful? Give feedback.
-
|
Another idea, using single quotes |
Beta Was this translation helpful? Give feedback.
-
|
Also I was thinking about adding a "wrapper" for backticks. To denote beginning and end of string. Although it solves array of backticks problem, I think it looks more ugly and make writing single line raw strings too difficult. |
Beta Was this translation helpful? Give feedback.
-
|
I think either system (a Zig-style prefix token for each line or a Python-style prefix token for the whole block) has merits and the precise choice will come down to preference... 😅 If I can prompt a (potentially dangerous) question: What if there were an adopted "special" character which can placed directly after a block-string leader that specifies that identical leading whitespace from each line is stripped? e.g., This would evaluate to: As maligned as YAML can be, I do feel that its support for multi-line string support feels extremely nice for, e.g., embedding aligned text or code snippets while not disrupting the overall flow of the document. This does come at the cost of some expressiveness in the grammar—I don't know of a way to denote retained vs. discarded whitespace in ABNF—but perhaps the trade-off is worthwhile. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks everyone for the thoughtful input. After weighing the trade-offs, we’ve decided to stick with the existing triple-quoted multiline strings. The explicit start/end delimiter is clearer for readers and tooling, and avoids the added complexity and potential confusion of Zig-style line-prefixed strings. Closing this discussion. |
Beta Was this translation helpful? Give feedback.

Thanks everyone for the thoughtful input. After weighing the trade-offs, we’ve decided to stick with the existing triple-quoted multiline strings. The explicit start/end delimiter is clearer for readers and tooling, and avoids the added complexity and potential confusion of Zig-style line-prefixed strings. Closing this discussion.