Skip to content

Consider Zig-style multiline strings #3

Description

@omentic

Hi, I noticed you've added multiline strings with the usual """ triple quote syntax.

I think the triple quote syntax is a bad multiline string syntax. It's the de facto standard, of course, but I think the de facto standard is bad. You can't nest quotes without escapes, you can't indent multiline strings to be at the same level as the rest of the code (or if you do you have to cut off some leading characters, arbitrarily), you can't insert raw characters directly (or if you do you have to change how your trailing """ works).

There is an approach taken by Zig which fixes all of these points. They use a prefix operator \\ that behaves much like //. It recognizes anything until the end of the line, and then -- if there is a \\ starting the next line -- appends it to the previous one, inserting a newline in between. This means that multiline strings can be indented at any level and \\ and """ and any sort of raw character can exist freely since \\ recognizes anything until the end of the line. It's pretty nice IMO.

{
  notes: \\This is a multiline strings.
         \\Keeps formatting as-is.
}

This of course doesn't work if you want to be whitespace-and-newline insensitive like JSON, but given you've got multiline strings I'd imagine that's not a goal of the project to begin with.

Anyway, cheers! Just something to consider.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions