Add string interpolation (\(expr) syntax)#257
Merged
Conversation
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 )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #230. Adds Swift-style
\(expr)string interpolation — the fourth and final item in the string builtins roadmap (#198 → #210 → #213 → #230)."hello \(@String.0)","x = \(@Int.0)","a=\(@Int.1), b=\(@Int.0)"*_to_stringbuilt-inInterpolatedStringis a first-class AST node that survives formatting (no desugaring tostring_concatchains at source level)\(...)cannot contain string literals (regex lexer limitation; useletbindings)Files changed (21 files, +682/-40)
Compiler core (9 files):
vera/ast.py—InterpolatedStringdataclass +format_exprupdatevera/transform.py—_split_interpolation,_parse_interp_expr,STRING_LIT/string_lithandlersvera/checker/expressions.py— type synthesis with_TO_STRING_TYPESauto-conversion mapvera/errors.py— E148 error codevera/formatter.py— round-trip\(expr)renderingvera/wasm/inference.py—InterpolatedString→i32_pairin 3 dispatchersvera/wasm/context.py— expression dispatcher +_is_pair_exprvera/wasm/operators.py—_translate_interpolated_string(desugars to synthetic FnCall nodes)vera/codegen/modules.py— guard rail recurse into interpolation partsTests (18 new tests):
ch04_string_interpolation(conformance suite: 43→44 programs)Documentation:
Test plan
mypy vera/— clean (41 source files)pytest tests/ -v— 1,899 tests collected, 1,893 passed, 6 skipped, 0 failedpython scripts/check_conformance.py— all 44 conformance programs passpython scripts/check_examples.py— all 18 examples passpython scripts/check_spec_examples.py— all spec code blocks passpython scripts/check_skill_examples.py— all SKILL.md code blocks passpython scripts/check_version_sync.py— version 0.0.76 consistent🤖 Generated with Claude Code