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
//! # Sigil-Stitch
//!
//! Type-safe, import-aware, width-aware code generation for multiple languages.
//!
//! Sigil-Stitch combines JavaPoet's builder + CodeBlock model with Wadler-Lindig
//! pretty printing and multi-language support. Reference types with `%T` in format
//! strings, and the library tracks every import for you, resolves naming conflicts,
//! and emits width-aware formatted output.
//!
//! ## Format Specifiers
//!
//! | Specifier | Name | Argument Type | Purpose |
//! |-----------|------|---------------|---------|
//! | `%T` | Type | `TypeName<L>` | Emit type reference, track import |
//! | `%N` | Name | `&str` or `Nameable` | Emit identifier name |
//! | `%S` | String | `&str` | Emit escaped string literal |
//! | `%L` | Literal | `&str`, number, `CodeBlock<L>` | Emit raw value or nested block |
//! | `%W` | Wrap | (none) | Soft line break point |
//! | `%>` | Indent | (none) | Increase indent level |
//! | `%<` | Dedent | (none) | Decrease indent level |
//! | `%[` | Statement begin | (none) | Start of statement |
//! | `%]` | Statement end | (none) | End of statement (appends `;` if needed) |
//!
//! ## Quick Example
//!
//! ```rust
//! use sigil_stitch::prelude::*;
//! use sigil_stitch::lang::typescript::TypeScript;
//!
//! let user_type = TypeName::<TypeScript>::importable_type("./models", "User");
//!
//! let mut cb = CodeBlock::<TypeScript>::builder();
//! cb.add_statement("const user = await getUser(%S)", ("id",));
//! cb.add_statement("return user as %T", (user_type.clone(),));
//! let body = cb.build().unwrap();
//!
//! let mut fb = FileSpec::<TypeScript>::builder("user.ts");
//! fb.add_code(body);
//! let file = fb.build().unwrap();
//!
//! let output = file.render(80).unwrap();
//! assert!(output.contains("import type { User } from './models'"));
//! ```
//!
//! ## `sigil_quote!` Macro
//!
//! For less ceremony, write target-language code inline with the `sigil_quote!` macro:
//!
//! ```
//! use sigil_stitch::prelude::*;
//! use sigil_stitch::lang::typescript::TypeScript;
//!
//! let user_type = TypeName::<TypeScript>::importable_type("./models", "User");
//!
//! let block = sigil_quote!(TypeScript {
//! const user: $T(user_type) = await getUser($S("id"));
//! if (!user) {
//! throw new Error($S("not found"));
//! }
//! return user;
//! }).unwrap();
//! ```
//!
//! Interpolation markers: `$T` (type), `$N` (name), `$S` (string literal),
//! `$L` (literal), `$C` (nested code block), `$W` (soft line break), `$$` (escape).
//!
//! See the full guide at `doc/src/sigil_quote.md` for control flow, limitations,
//! and advanced usage.
/// Composable code fragments with format specifiers (`%T`, `%N`, `%S`, `%L`, etc.).
/// Rendering engine that walks `CodeBlock` format parts into final output.
/// Reusable named-parameter templates that produce `CodeBlock`s.
/// Error types for sigil-stitch.
/// Import types, grouping, and conflict resolution.
/// Walks `CodeBlock` trees to extract all import references.
/// Language abstraction trait and per-language implementations.
/// Collision-free name allocation for generated identifiers.
/// Structural builders (TypeSpec, FunSpec, FileSpec, etc.) that emit `CodeBlock`s.
/// Type references with recursive import tracking and pretty-printing.
/// Common re-exports for convenient usage.