Generate value nodes; introduce field-type override + hand-written-union skip#95
Merged
Merged
Conversation
This was referenced Jun 10, 2026
Member
Author
This was referenced Jun 10, 2026
Merged
Member
Author
Merge activity
|
…ion skip
This PR brings the `value` category into the generator: 16 node structs are emitted under `codama-nodes/src/generated/value_nodes/`, plus the renamed `EnumVariantData` inline union (`enumValuePayload` in the spec). Hand-written `value_nodes/*.rs` files shrink to constructors and `#[cfg(test)] mod tests`, mirroring the established pattern. Three pieces of generator infrastructure land alongside, each driven by a one-entry config that future PRs can extend or simplify: `HAND_WRITTEN_UNIONS` skips category unions whose Rust counterpart can't be reproduced mechanically (currently the `value` category's `valueNode`, hosted as the hand-written `RegisteredValueNode` with `#[derive(RegisteredNodes)]`); `FIELD_TYPE_OVERRIDES` pins a specific `(node, attr)` pair to a bespoke Rust type when the spec can't capture it (currently `numberValueNode.number \u2192 Number`, since the spec says `float(f64)` but Rust uses a `Number` enum with a `serde(from/into = "JsonNumber")` adapter and eight `From<uN/iN/fN>` impls \u2014 all kept hand-written in `number_value_node.rs`); and `UNION_NAME_OVERRIDES` gains an entry for `enumValuePayload \u2192 EnumVariantData`. The inline-union emit path also now uses the Rust override name (when present) for the on-disk file name, so `enumValuePayload` lands at `enum_variant_data.rs` matching its type name. The `enum` Rust keyword is added to the field-name escape set (`enumValueNode.enum \u2192 r#enum`). Box rule applies: `constantValueNode.{type,value}`, `mapEntryValueNode.{key,value}`, `someValueNode.value`, `structFieldValueNode.value`, and `enumValueNode.value` (as `Box<Option<EnumVariantData>>`) are all boxed; the corresponding hand-written constructors use `Box::new(...)` and tests dereference with `*`.
5b769a4 to
7bf6396
Compare
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.

This PR brings the
valuecategory into the generator: 16 node structs are emitted undercodama-nodes/src/generated/value_nodes/, plus the renamedEnumVariantDatainline union (enumValuePayloadin the spec). Hand-writtenvalue_nodes/*.rsfiles shrink to constructors and#[cfg(test)] mod tests, mirroring the established pattern. Three pieces of generator infrastructure land alongside, each driven by a one-entry config that future PRs can extend or simplify:HAND_WRITTEN_UNIONSskips category unions whose Rust counterpart can't be reproduced mechanically (currently thevaluecategory'svalueNode, hosted as the hand-writtenRegisteredValueNodewith#[derive(RegisteredNodes)]);FIELD_TYPE_OVERRIDESpins a specific(node, attr)pair to a bespoke Rust type when the spec can't capture it (currentlynumberValueNode.number \u2192 Number, since the spec saysfloat(f64)but Rust uses aNumberenum with aserde(from/into = "JsonNumber")adapter and eightFrom<uN/iN/fN>impls \u2014 all kept hand-written innumber_value_node.rs); andUNION_NAME_OVERRIDESgains an entry forenumValuePayload \u2192 EnumVariantData. The inline-union emit path also now uses the Rust override name (when present) for the on-disk file name, soenumValuePayloadlands atenum_variant_data.rsmatching its type name. TheenumRust keyword is added to the field-name escape set (enumValueNode.enum \u2192 r#enum). Box rule applies:constantValueNode.{type,value},mapEntryValueNode.{key,value},someValueNode.value,structFieldValueNode.value, andenumValueNode.value(asBox<Option<EnumVariantData>>) are all boxed; the corresponding hand-written constructors useBox::new(...)and tests dereference with*.