Commit 632365f
authored
Generate Rust type nodes (#103)
This PR generates 21 of the 28 `type`-category nodes from `@codama/spec`, completing first-class generation support for all 8 spec categories. The 7 nestable wrappers (`fixedSize`, `sizePrefix`, `pre/postOffset`, `sentinel`, `hiddenPrefix/Suffix`) and the four type-category unions stay hand-written, since they carry generic variant types, a cross-category Link member, and bespoke `TryFrom` bridges that don't fit the standard renderers — and they're the natural deletion boundary if a future spec drops nested unions.
The generator gains a `NodeMacroFlavor` classifier (`nodeFlavor.ts`) that picks the emission macro per node from the spec: `nestedTypeNode.wrappers` are skipped, `enumVariantTypeNode` members and `structFieldTypeNode` get `#[node]`, and other type nodes get `#[type_node]`. `CategoryRouting` gains an `emitUnions` flag so `type` skips its bespoke unions, and `struct` joins the Rust keyword set so `enumStructVariantTypeNode.struct` renders as `r#struct`.
Reconciliation is mostly contained to `codama-nodes/src/type_nodes/`. Spec-driven type changes: `amountTypeNode.decimals → u32`, the enum-variant `discriminator → Option<u32>`, and `optionTypeNode.fixed → Option<bool>`. The box-all-union rule boxes `array/map/set.count → Box<CountNode>` and `structFieldTypeNode.{type, default_value}`, which cascades into a few `codama-attributes`/`codama-koroks`/`codama-korok-visitors` files and their tests. The hand-written nestable nodes are left untouched.
1008 cargo tests pass unchanged; `pnpm test` grew by 8 to 148; fmt, clippy, and the `pnpm generate` round-trip stay clean. The override surface is unchanged.1 parent a922a04 commit 632365f
71 files changed
Lines changed: 825 additions & 561 deletions
File tree
- codama-attributes/src/codama_directives
- type_nodes
- codama-korok-visitors
- src
- tests
- combine_types_visitor
- set_accounts_visitor
- set_events_visitor
- codama-koroks/src
- codama-nodes/src
- generated
- type_nodes
- type_nodes
- spec-generators
- src
- fragments
- test
- fragments
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
| 32 | + | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
243 | | - | |
| 243 | + | |
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
150 | 152 | | |
151 | 153 | | |
152 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
135 | 137 | | |
136 | 138 | | |
137 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
| 211 | + | |
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
| 207 | + | |
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| |||
0 commit comments