0276. Multi-line, raw and dedented string literals
- Status: Accepted (maintainer, 2026-11-22; recommended defaults for all open questions; frozen-file edits listed here approved)
- Date: 2026-11-22
- Plan: D4 (backlog); no plan task yet
- Review: Design Critic #6; extends 0019, 0039, 0268
Context
Prompts, JSON schemas, HTML templates and (with R2) regexes are
multi-line or backslash-heavy. Since the ADR-0268 cutover the
product reads compact source only
(driver::parse_file;
lexer.rs/parser.rs compile only under
the compact-migration feature). A compact string is
"N:payload. N counts bytes after escaping.
LF must be written \n, \ must be
\\, and the whole literal sits on its item's single
record line. Braces and quotes are already literal bytes, because
interpolation is a separate U part list. So the pain
for agents is a 40-line prompt on one line with a hand-counted
byte frame. A familiar-syntax """ alone would fix
nothing: no product reader accepts it. LANGUAGE.md says "Strings
cannot cross lines" (budget 6250, nearly full).
Decision
Values. Every new form decodes to the existing
AST Str (or a part of Interpolation).
Values are ordinary str, with no IR, C, runtime or
interpreter change. ExprKind::Str gains a spelling
tag Plain | Block, so formatting preserves the
author's form and never converts between them.
Compact text block (the authoring form). A new
expression opcode `N; (free today) means "the next N
continuation lines". After the record's LF, the reader takes each
block's lines in opcode order. Every line is |
followed by raw bytes up to LF. No top-level record starts with
|.
- Content is raw: no escapes and no interpolation.
\,{,"and tab are literal. CR and other C0 controls are rejected. Source stays LF-only. - The value is the lines joined by LF, with no trailing LF. A
final bare
|line adds one. Trailing spaces are content, and fmt keeps them. - To interpolate, put blocks inside
Uparts:U3;`2;a`1;and then three|lines. - Lines are counted, not bytes, because agents count lines reliably. The 1 MiB per-string and 65,535-element bounds apply. A record's span includes its continuation lines.
!prompt:>s`3;
|You review diffs. Reply with JSON only:
|{"ok": true, "notes": ["..."]}
|Never use \t or prose.
Familiar spelling (docs, ast.rs
printer, migration reader):
"""must be followed by LF. Content on the opening line is an error.- The closing
"""sits alone on its own line. The whitespace before it is the indent prefix, and it is stripped byte-for-byte from every content line. - Lines that are only whitespace become empty. A non-blank line without the full prefix is an error. A prefix that mixes tabs and spaces is an error. Tabs after the prefix are content.
- The LF before the closing delimiter is dropped (as in Swift).
- Escapes
\n \t \r \\ \" \0,{x}interpolation and{{/}}work as in"…"."needs no escape, and\"""escapes a delimiter. - Raw strings are spelled one way only, Swift-style:
#"…"#and#"""…"""#. They have no escapes and no interpolation,"#ends them, and the multi-line form uses the same dedent rules.#is unused in familiar Tenon, so there is no lookahead clash with an identifierr. - The encoder emits a Block when every decoded part fits block
rules. Otherwise it emits a
"frame (for example, a value with CR or NUL).
Diagnostics.
- Compact: E0125 with a distinct message and edit for each case:
missing continuation line (unterminated), stray
|line, control byte, and N = 0. - Familiar (migration build, E0001–E0099): unterminated reuses
E0001, with help that names
""". Content after the opening""", closing not alone, insufficient indent and a mixed tab/space prefix share one new code, E00xx (allocate at implementation).
LANGUAGE.md replaces the "Strings cannot cross lines; escapes: …" sentence with (+≈35 tokens; spec-keeper trims ≈35 elsewhere, e.g. the smallest-i64 example):
Strings: escapes
\n \t \r \\ \" \0. Text blocks are compact`N;plus N raw|lines (familiar"""dedented to the closing line, raw#"…"#/#"""): no escapes or interpolation inside; joined by LF, no final LF.
Prior art
- Swift SE-0168 multi-line literals (closing-delimiter indent): https://github.com/swiftlang/swift-evolution/blob/main/proposals/0168-multi-line-string-literals.md
- Swift SE-0200
#"…"#raw strings: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0200-raw-string-escaping.md - Java text blocks, JEP 378: https://openjdk.org/jeps/378
- Zig per-line
\\multiline literals (line prefix, no dedent): https://ziglang.org/documentation/master/#Multiline-String-Literals - C# 11 raw string literals: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/raw-string
Alternatives considered
- Familiar
"""only, compact keeps\nframes. This matches the original brief. It is not enough, because authors write compact source and never see""". - Allow raw LF inside a byte-counted
"frame. Agents would still count bytes across lines, and record splitting at LF would break. - Rust
r"…"/r#"…"#. This adds hash levels and an identifier-adjacent prefix.#"…"#needs one level, and"#is rare. - Kotlin
trimIndent()as a library call. It is a runtime cost, its dedent rules are implicit, and it cannot be checked at compile time.
Consequences
- UX: prompts and schemas in shipped tools are byte-exact and readable in source. Values are unchanged.
- DX: diffs show one prompt line per source line, and JSON or regex are pasted verbatim.
- AX (ADR-0009): there is one raw compact form, it is counted in lines, and checkable edits fix miscounts. Teaching costs one primer card.
- The familiar
"""form keeps two flavors, escaped and raw. That is the price of matching the maintainer's choice in docs. Compact has one. - Item hashes may change for literals re-spelled as blocks (see open question 2).
- Frozen files: none. The interpreter shares
driver::parse_file.
Implementation slices
- Compact block form:
`opcode,|continuation lines,Strspelling tag, encoder and canonical checks, reader unit tests. Areas:compact.rs,compact/{reader,expr,encode}.rs,ast.rs,PRIMITIVE_GRAMMAR.md. Frozen files: no. Agent: Claude Sonnet. - Tooling for multi-line records:
compact_tools.rs(focus, holes, replace, probe),outline.rsspans,fmt.rs,edit.rs, and thecompact help primercard. Frozen files: no. Agent: Claude Sonnet. - Familiar spelling: the
ast.rsprinter, plus"""/#"in the migrationlexer.rs/compact/migration.rs(feature-gated), with dedent unit tests. Frozen files: no. Agent: OpenCode. - Docs: LANGUAGE.md text above, an IDIOMS prompt idiom (≤3
lines), diagnostics.md rows and a
teach-core.tsvcard. Frozen files: no. Agent: Gemini (agy Argon Low).
Open questions (resolved)
Resolved by maintainer on 2026-11-22: every question takes its stated default.
- Should the compact text block (
`N;with|lines) be the authoring form? Default: yes. Without it,"""exists only in docs. - Should item hashes include the Plain/Block spelling tag? Default: yes, like binder spellings, with no special-casing.
- Should slice 3 build the familiar reader (migration build) or only the printer? Default: printer only, plus the reader if the migration utility outlives D4.
- Should the continuation prefix be
|or"? Default:|, which is distinct from the"frame opcode. - Should fmt ever suggest a block for a long Plain string with
\n? Default: no. Keep the author's form.