Expand description
Typed AST → ParseTree reverse walk (DslDump).
DslBuild turns a validated ParseTree into a
typed AST value; this module is its inverse. A type deriving
#[derive(DslDump)] (in dsl-kit-macros) re-emits the tree shape
its own DslBuild derive accepts, so the two derives stay a
round-trip pair by construction:
from_parse_tree(&ast.to_parse_tree()?, &ids) ≙ ast (modulo NodeId)Chaining the emitted tree through
to_canonical_json yields
the serde-bridge JSON serializer downstream consumers want — see
dump_canonical_json. Because to_canonical_json runs
check_conformance on the way down, a
derive bug that emitted a non-conforming shape surfaces as loud
diagnostics rather than silently wrong JSON.
§Emission rules (the duals of the build defaults)
id: NodeIdis not serialized — re-parsing mints fresh ids, which is the same contract every front-end already has. The id is only used to look up the node’s$allowannotation in the caller-suppliedAllowTable.- An absent
Option<T>payload / child omits its key entirely (nevernull), matching the canonical-JSON spelling andbuild_field_optional’s absent →Nonerule. Vec<T>payloads always emit, including as[]when empty — one unambiguous spelling. (build_field_vecaccepts the omitted spelling too, so both round-trip; the emit side just never produces it.)Vec<Self>child slots always emit the slot, including empty. A slot declarednon_emptyfails conformance downstream in that case, which is the declared-constraint violation surfacing — not something to paper over here.- Keyed slots (
BTreeMap) emit in map iteration order, which is already ascending by key — the sortednesscheck_conformancedemands. Empty maps omit the slot (the PEG front-end’s “nothing to record” spelling; both spellings are accepted everywhere it matters). - Spans are
None: a synthesized tree has no source text.
One known asymmetry, inherited rather than introduced: nested
Option<Option<T>> payloads cannot distinguish Some(None) from
None in JSON (both spell as an absent key / null), exactly as on
the build side.
Traits§
Functions§
- dump_
canonical_ json - Serializes a typed AST straight to canonical serde-bridge JSON:
DslDump::to_parse_treechained throughto_canonical_jsonagainst the type’s own derived schema. - dump_
canonical_ json_ with dump_canonical_jsonwith anAllowTableso$allowannotations survive into the JSON (and therefore into content hashes computed over it).- dump_
child_ many - Emits a
Multiplicity::Manychild slot — always, including as an empty slot, so the emitted spelling is unambiguous. Dual ofbuild_child_many. - dump_
child_ map - Emits a
Multiplicity::Mapchild slot from(key, node)entries, omitting the slot when empty. Dual ofbuild_child_map. - dump_
child_ one - Emits a
Multiplicity::Onechild slot. Dual ofbuild_child_one. - dump_
child_ optional - Emits a
Multiplicity::Optionalchild slot, omitting the slot entirely whenNone. Dual ofbuild_child_optional. - dump_
field - Serializes one payload field into the tree as
RawValue::Json. - dump_
field_ optional - Serializes an optional payload field, omitting the key when
None. - dump_
scalar_ map - Emits a scalar-valued keyed slot (
BTreeMap<String, V>whereVis a payload type) as keyed entries each carrying a singlevaluefield — the exact shape the JSON front-end builds on ingest andbuild_scalar_mapreads back. Omits the slot when the map is empty.