Skip to content

Better support multiline strings (herdocs) and string tagging #77

@MatheusRich

Description

@MatheusRich

Lit should support multiline string blocks for embedding SQL, JSON, Markdown, regexes, etc. A block can optionally be labeled (@sql, @json, etc.) so editors can apply syntax highlighting, but the label is not required.

Syntax:

[@<label>]
<marker><content>
<marker><content>
...
  • The first content line determines the mode:

    • ''' → raw (no escapes, no interpolation)
    • """ → interpolated (supports escapes and #{…})
  • Every body line must start with the same marker.

  • Everything after the marker is included verbatim (spaces preserved).

  • A line that is just the marker produces a blank line (\n).

  • To include a literal leading quote, add one extra quote ('''' or """").

  • The block ends at the first line that doesn’t start with the marker.

Examples

Raw SQL:

@sql
'''SELECT *
'''FROM users
'''WHERE id = 42

Interpolated SQL:

@sql
"""SELECT *
"""FROM users
"""WHERE id = #{user_id}

JSON (no label):

'''{
'''  "ok": true,
'''  "id": 42
'''}

Single-line form:

let query = @sql """SELECT * FROM users WHERE id = #{id}
let json  = '''{"ok": true, "id": 42}

This design keeps the marker visible on every line (like Zig) while @label provides a clean way for editors to apply language-aware highlighting.

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