BoundaryML
baml
BlogDocsChangelog

feat(baml_syntax): Add Rowan-based syntax tree infrastructure for BAML

#2687Merged
Comparing
hellovai/syntax
(
d28d9bd
) with
canary
(
4429f4b
)
CodSpeed Performance Gauge
-1%
Untouched
12

Benchmarks

Passed

bench_incremental_no_change
crates/baml_tests/benches/compiler_benchmark.rs
CodSpeed Performance Gauge
+1%
21.2 µs21.1 µs
bench_lexer_only_simple
crates/baml_tests/benches/compiler_benchmark.rs
CodSpeed Performance Gauge
0%
52.5 µs52.4 µs
bench_parse_only_simple
crates/baml_tests/benches/compiler_benchmark.rs
CodSpeed Performance Gauge
0%
74.4 µs74.3 µs
bench_incremental_add_new_file
crates/baml_tests/benches/compiler_benchmark.rs
CodSpeed Performance Gauge
0%
21.8 µs21.8 µs
bench_incremental_modify_function
crates/baml_tests/benches/compiler_benchmark.rs
CodSpeed Performance Gauge
0%
21.9 µs22 µs
bench_incremental_add_field
crates/baml_tests/benches/compiler_benchmark.rs
CodSpeed Performance Gauge
0%
21.9 µs22 µs
bench_scale_deep_nesting
/actions-runner/_work/baml/baml/baml_language/target/release/build/baml_tests-74008be547e634ff/out/generated_benchmarks.rs
CodSpeed Performance Gauge
-1%
1.1 ms1.1 ms
bench_incremental_add_user_field
/actions-runner/_work/baml/baml/baml_language/target/release/build/baml_tests-74008be547e634ff/out/generated_benchmarks.rs
CodSpeed Performance Gauge
-1%
1.1 ms1.1 ms
bench_empty_project
crates/baml_tests/benches/compiler_benchmark.rs
CodSpeed Performance Gauge
-1%
1 ms1 ms
bench_scale_100_functions
/actions-runner/_work/baml/baml/baml_language/target/release/build/baml_tests-74008be547e634ff/out/generated_benchmarks.rs
CodSpeed Performance Gauge
-1%
1.1 ms1.1 ms
bench_incremental_rename_type
/actions-runner/_work/baml/baml/baml_language/target/release/build/baml_tests-74008be547e634ff/out/generated_benchmarks.rs
CodSpeed Performance Gauge
-1%
1.1 ms1.1 ms
bench_single_simple_file
crates/baml_tests/benches/compiler_benchmark.rs
CodSpeed Performance Gauge
-1%
1.1 ms1.1 ms

Commits

Click on a commit to change the comparison range
Base
canary
4429f4b
-0.57%
feat(baml_syntax): Add Rowan-based syntax tree infrastructure for BAML Introduces a lossless, incremental syntax tree representation for BAML source code using the Rowan library (same as rust-analyzer). This provides the foundation for all language tooling including parsing, semantic analysis, and IDE features. ## What is a Syntax Tree? A syntax tree represents the grammatical structure of source code. Unlike traditional ASTs, Rowan syntax trees are: - Lossless: preserve all source text including whitespace and comments - Incremental: support efficient updates when code changes - Lazy: nodes are created on-demand during traversal - Parent-aware: nodes can traverse up to their parents ## Key Components **SyntaxKind**: Defines all possible elements in BAML code - Tokens: WORD, INTEGER, L_BRACE, ARROW, etc. - Nodes: FUNCTION_DEF, CLASS_DEF, TYPE_EXPR, etc. **Typed AST Nodes**: Provide ergonomic access to tree structure ```rust // Example from tests: let function = source_file.items() .find_map(|item| match item { Item::Function(f) => Some(f), _ => None, }) .unwrap(); assert_eq!(function.name().unwrap().text(), "GetUser"); ``` **Tree Builder**: Enables programmatic tree construction for testing ```rust let tree = SyntaxTreeBuilder::build_function( "GetUser", &[("id", "int"), ("name", "string")], "User" ); // Produces: function GetUser(id: int, name: string) -> User { ... } ``` **Traversal Utilities**: Navigate and query syntax trees - Find nodes by type at specific text positions - Search for ancestors/descendants of specific kinds - Filter out trivia (whitespace/comments) when needed ## Why This Matters This infrastructure enables: - Error-resilient parsing (partial trees even with syntax errors) - Incremental re-parsing (only changed portions) - Precise source locations for diagnostics - Code formatting that preserves comments - Refactoring tools that maintain code style - IDE features like go-to-definition and hover The lossless property means we can perfectly reconstruct the original source, essential for formatters and refactoring tools that need to preserve user intent.
d28d9bd
5 days ago
by hellovai
© 2025 CodSpeed Technology
Home Terms Privacy Docs