Commit d028fbd
authored
BEP-049 M1–M4: backtick strings, interpolation, control flow, tagged templates (#3577)
Implements [BEP-049](https://beps.boundaryml.com/beps/49) (String
Interpolation) milestones **M1 through M4**.
## What's in this PR
**M1 — backtick string literals** `` `...` ``: new `BACKTICK` token,
multi-tick delimiter ladders, escapes, multi-line auto-dedent (§12),
usable in any expression position.
**M2 — `${expr}` interpolation**: `${...}` as a block expression (§4),
implicit `.to_string()` for non-string values (§11), and **strict typing
(§7/§11)** — interpolating a nullable or non-stringable value is a
compile-time error.
**M3 — block control flow**: `${for (let x in xs)}…${endfor}`, `${if
(c)}…${else if}…${else}…${endif}` using host syntax, with §13 whitespace
control.
**M4 — tagged templates** (§10): `` tag`...` `` with the
`//baml:tagged_string` marker, `TaggedString { parts, values }`, tag
resolution + signature validation, body-lambda params scoping into
`${…}`, and **full VM execution** — static layouts (M4e.1a) and
`${for}`/`${if}` runtime flattening (M4e.1b).
## Architecture: check-then-lower (clean diagnostics)
Both backtick forms are unified behind a first-class `Expr::Template {
tag: Default { elaborated } | Custom { tag, body }, segments }` node
that survives through TIR. Untagged backticks no longer desugar early —
interpolation diagnostics point at the original `${…}` span instead of
leaking a synthetic `.to_string()` call. This matches how tagged
templates (and TypeScript) check the structured node and lower late.
## Testing
Full workspace suite green. Adds unit + runtime coverage for backtick
literals, interpolation, strict-type diagnostics, control flow, and
tagged-template execution (static, `${for}`/`${if}`, nested, mixed,
captures, body-param injection, nested lambdas capturing loop-locals).
## Not in this PR
M5 (built-in `prompt` tag), M6 (legacy `#"..."#` interop + migrator), M7
(drop minijinja).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* BEP-049 backtick string literals with `${}` interpolation, including
`${for}` / `${if}` control-flow.
* Tagged templates with custom tag expressions and structured
`TaggedString` template metadata.
* Backtick-aware LLM prompts using prompt closures, plus typed
prompt/context helpers in the standard library.
* **Improvements**
* BEP-049 dedentation and block-tag trimming for multiline literals.
* Extended escape decoding with backtick-specific line-ending
normalization.
* Formatter/lexer/parser now properly recognize and preserve backtick
delimiter/interpolation syntax.
* **Bug Fixes**
* More precise template diagnostics and improved diagnostic span
stability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 2f72dba commit d028fbd
160 files changed
Lines changed: 17618 additions & 2547 deletions
File tree
- baml_language
- .cargo
- .ci/size-gate
- crates
- baml_base/src
- baml_builtins2/baml_std/baml
- ns_llm
- baml_cli/src/snapshots
- baml_compiler2_ast/src
- baml_compiler2_emit/src
- baml_compiler2_hir/src
- baml_compiler2_mir/src
- baml_compiler2_ppir/src
- baml_compiler2_tir/src
- baml_compiler2_visualization/src/control_flow
- baml_compiler_lexer/src
- baml_compiler_parser/src
- baml_compiler_syntax
- src
- baml_fmt/src
- ast
- baml_lsp2_actions/src
- baml_tests
- projects
- compiles/backtick_strings
- diagnostic_errors
- backtick_strict_types
- control_flow
- snapshots
- baml_src
- broken_syntax
- banned_expressions
- error_cases
- is_in_type_position
- mismatched_brackets
- namespaces_same_name
- parser_error_recovery
- type_annotation_errors
- compiles
- __assert_std__
- __baml_std__
- __testing_std__
- backtick_strings
- bigint_literal
- comment_in_type
- deep_method_call
- host_callable_call
- is_operator
- json_alias_basic
- json_cross_namespace_static_call
- json_llm_return_type
- json_map_literal
- json_to_from_string_composite_generic
- json_to_from_string_concrete
- json_to_from_string_generic_forwarding
- json_to_from_string_three_level
- lambda_fat_arrow
- lambda_field_access
- lexical_scoping
- llm_image_outputs
- numeric_invariance_ok
- optional_function_parameters
- paren_union_test
- patterns_new
- reflect_type_of_user_generic
- stream_llm_inferred_typeargs
- testset_vibes_nested
- type_annotation
- type_builder_errors
- type_builder_test
- diagnostic_errors
- assignment_expr_position
- backtick_strict_types
- captured_field_chain
- catch_return_type_mismatch
- catch_throw_regressions
- control_flow
- format_checks
- generic_call_ambiguity
- generics
- instanceof_removed
- is_pattern_negative
- json_static_method_arity
- match_exhaustiveness
- numeric_invariance
- patterns_new
- runtime_id_misuse
- stream_types
- test_with_runner_ambiguity
- type_reflection_strict
- unknown_type_error
- src/compiler2_tir
- snapshots
- tests
- bytecode_format/snapshots
- bex_engine/tests
- bex_vm/src/package_baml
- sys_llm/src
- sys_ops/src
- tools_onionskin/src
- sdks/python
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
0 commit comments