Skip to content

Add string interpolation (\(expr) syntax)#257

Merged
aallan merged 1 commit into
mainfrom
feat/230-string-interpolation
Mar 10, 2026
Merged

Add string interpolation (\(expr) syntax)#257
aallan merged 1 commit into
mainfrom
feat/230-string-interpolation

Conversation

@aallan

@aallan aallan commented Mar 10, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #230. Adds Swift-style \(expr) string interpolation — the fourth and final item in the string builtins roadmap (#198#210#213#230).

  • Syntax: "hello \(@String.0)", "x = \(@Int.0)", "a=\(@Int.1), b=\(@Int.0)"
  • Auto-conversion: Non-String expressions of type Int, Nat, Bool, Byte, Float64 are auto-wrapped with the appropriate *_to_string built-in
  • Canonical form: InterpolatedString is a first-class AST node that survives formatting (no desugaring to string_concat chains at source level)
  • Full pipeline: Touches every compiler stage — transformer, type checker (E148 for unsupported types), formatter, WASM codegen
  • Limitation: Expressions inside \(...) cannot contain string literals (regex lexer limitation; use let bindings)

Files changed (21 files, +682/-40)

Compiler core (9 files):

  • vera/ast.pyInterpolatedString dataclass + format_expr update
  • vera/transform.py_split_interpolation, _parse_interp_expr, STRING_LIT/string_lit handlers
  • vera/checker/expressions.py — type synthesis with _TO_STRING_TYPES auto-conversion map
  • vera/errors.py — E148 error code
  • vera/formatter.py — round-trip \(expr) rendering
  • vera/wasm/inference.pyInterpolatedStringi32_pair in 3 dispatchers
  • vera/wasm/context.py — expression dispatcher + _is_pair_expr
  • vera/wasm/operators.py_translate_interpolated_string (desugars to synthetic FnCall nodes)
  • vera/codegen/modules.py — guard rail recurse into interpolation parts

Tests (18 new tests):

  • 9 type checker tests (auto-conversion for all types, unsupported type error, multiple exprs)
  • 9 codegen end-to-end tests (basic string, int/bool/nat/float conversion, multiple parts, nested fn calls)
  • New conformance test ch04_string_interpolation (conformance suite: 43→44 programs)

Documentation:

  • Spec §1.4 "String Interpolation" and §4.13.1 "String Interpolation"
  • SKILL.md interpolation examples
  • CHANGELOG v0.0.76

Test plan

  • mypy vera/ — clean (41 source files)
  • pytest tests/ -v — 1,899 tests collected, 1,893 passed, 6 skipped, 0 failed
  • python scripts/check_conformance.py — all 44 conformance programs pass
  • python scripts/check_examples.py — all 18 examples pass
  • python scripts/check_spec_examples.py — all spec code blocks pass
  • python scripts/check_skill_examples.py — all SKILL.md code blocks pass
  • python scripts/check_version_sync.py — version 0.0.76 consistent
  • Pre-commit hooks pass (mypy, pytest, conformance, examples, allowlists)

🤖 Generated with Claude Code

Implements #230. Adds Swift-style \(expr) interpolation inside
double-quoted strings with auto-conversion for Int, Nat, Bool, Byte,
and Float64. InterpolatedString is a first-class AST node (canonical
form) touching every compiler stage: transformer, type checker,
formatter, and WASM codegen.

- New AST node InterpolatedString with parts tuple
- Transformer: _split_interpolation + _parse_interp_expr helpers
- Type checker: auto-to_string dispatch with E148 for unsupported types
- Formatter: round-trip preserving \(expr) syntax
- WASM codegen: desugars to string_concat/to_string chains
- 18 new tests (9 checker + 9 codegen end-to-end)
- New conformance test ch04_string_interpolation (44 programs)
- Spec sections 1.4 and 4.13.1 documenting the feature

Co-Authored-By: Claude <noreply@anthropic.invalid>
EOF
)
@aallan aallan merged commit aa75344 into main Mar 10, 2026
10 checks passed
@aallan aallan deleted the feat/230-string-interpolation branch March 10, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

String interpolation

1 participant