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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//! The put-direction of the parse / decorate / emit lens.
//!
//! `decorate` attaches a complete layout enrichment fibre to an
//! [`AbstractSchema`](panproto_schema::AbstractSchema), producing a
//! [`DecoratedSchema`](panproto_schema::DecoratedSchema) that
//! `emit_pretty_with_protocol` can render byte-for-byte. It is a
//! section of the schema-level forgetful U
//! [`DecoratedSchema::forget_layout`](panproto_schema::DecoratedSchema::forget_layout)
//! at the granularity of kind- *and* edge-multiset equivalence (the
//! ordering invariant — vertex IDs are reborn by the re-parse).
//!
//! ## Implementation strategy
//!
//! 1. Render the abstract schema to canonical bytes via
//! `emit_pretty_with_policy`. The de-novo emitter walks
//! `grammar.json` production rules driven by the caller-supplied
//! [`LayoutPolicy`].
//!
//! 2. Re-parse those bytes. The parse walker attaches the full layout
//! fibre (`start-byte`, `end-byte`, every `interstitial-N`,
//! `chose-alt-fingerprint`, `chose-alt-child-kinds`) and invents
//! fresh vertex IDs.
//!
//! Step 2's ID renaming is intrinsic to the parse walker: tree-sitter
//! reparses can consolidate or fragment tokens at boundaries that the
//! emit pipeline doesn't know how to mirror (e.g. lilypond's
//! `c'4` parses as a single note even when the emitter rendered three
//! tokens `c`, `'`, `4`). Recovering vertex IDs from the abstract
//! input by parallel walk therefore *cannot* succeed for all
//! grammars; the documented section law holds at the standard
//! granularity of [`kind_multiset`](panproto_schema::kind_multiset)
//! and [`edge_multiset`](panproto_schema::edge_multiset).
//!
//! ## Laws
//!
//! For every `a : AbstractSchema` and `p : LayoutPolicy`:
//!
//! - **Section law (mod kind- and edge-multiset):**
//! `kind_multiset(forget_layout(decorate(a, p)).as_schema()) ==
//! kind_multiset(a.as_schema())` AND
//! `edge_multiset(forget_layout(decorate(a, p)).as_schema()) ==
//! edge_multiset(a.as_schema())`,
//! for every protocol with a vendored grammar. The edge-multiset
//! half is the load-bearing one for sequenced data: order of notes
//! in a `Pattern<MidiEvent>`, of tokens in a parsed AST, of items
//! in a homogeneous list, would all collapse without it. Verified
//! by the `decorate_section_law` integration test.
//! - **Policy fidelity:** the bytes produced by `pretty_with_protocol`
//! honour every field of `p` (separator, newline, indent_width,
//! line_break_after, indent_open / close).
use ;
use ;
use LensError;
use ;
use crateParseError;
use crate;
use crateAstParser;
/// Decorate an abstract schema by routing through `emit_pretty_with_policy +
/// parse` against `parser`.
///
/// # Errors
///
/// Returns [`ParseError::EmitFailed`] when the abstract schema cannot
/// be rendered (missing grammar; vertex kind not a grammar rule), or
/// any other [`ParseError`] variant if the parser cannot re-ingest
/// its canonical output — the latter indicates a regression in the
/// parse/emit pipeline rather than a user bug.
/// Schema-level decorate driver shared by [`decorate_with_parser`] and
/// the [`ParserLayoutEnricher`] adapter installed in the lens crate's
/// enrichment registry.
/// Adapter exposing one registered parser as a
/// [`LayoutEnricher`](panproto_lens::enrichment_registry::LayoutEnricher).
///
/// Held by the global enrichment registry; one driver is installed
/// per protocol at [`ParserRegistry::register`](crate::ParserRegistry::register)
/// time so that
/// [`TheoryTransform::AddEnrichment`](panproto_gat::TheoryTransform::AddEnrichment)
/// dispatches to the right grammar walker without `panproto-lens`
/// depending on `panproto-parse`.
/// Install a layout-enrichment driver for `parser` into the global
/// enrichment registry. Called by
/// [`ParserRegistry::register`](crate::ParserRegistry::register).
pub