On this page

0276. Multi-line, raw and dedented string literals

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 |.

!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):

Diagnostics.

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

Alternatives considered

Consequences

Implementation slices

  1. Compact block form: ` opcode, | continuation lines, Str spelling 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.
  2. Tooling for multi-line records: compact_tools.rs (focus, holes, replace, probe), outline.rs spans, fmt.rs, edit.rs, and the compact help primer card. Frozen files: no. Agent: Claude Sonnet.
  3. Familiar spelling: the ast.rs printer, plus """/#" in the migration lexer.rs/compact/migration.rs (feature-gated), with dedent unit tests. Frozen files: no. Agent: OpenCode.
  4. Docs: LANGUAGE.md text above, an IDIOMS prompt idiom (≤3 lines), diagnostics.md rows and a teach-core.tsv card. Frozen files: no. Agent: Gemini (agy Argon Low).

Open questions (resolved)

Resolved by maintainer on 2026-11-22: every question takes its stated default.

  1. Should the compact text block (`N; with | lines) be the authoring form? Default: yes. Without it, """ exists only in docs.
  2. Should item hashes include the Plain/Block spelling tag? Default: yes, like binder spellings, with no special-casing.
  3. 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.
  4. Should the continuation prefix be | or "? Default: |, which is distinct from the " frame opcode.
  5. Should fmt ever suggest a block for a long Plain string with \n? Default: no. Keep the author's form.