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
//! The spec of the library's `transduce-tree`, for routers that run it
//! natively.
//!
//! `transduce-tree spec input` (`stdlib/transduce.alc`) makes a tree's
//! JSON events of a grammar's rule passes as `spec` says: a record keyed
//! by rule name, each entry a record of what that rule's passes do. The
//! library's text is the specification. A host's routers may run it
//! natively ([`crate::shared::Routers::transduce_tree`]), and the lowering
//! asks them to only when the program's spec has the standard shape
//! [`TreeSpec`] holds: every entry a record whose `:container` is
//! `:object` or `:array`, whose `:key` is a string or a token's index,
//! and whose `:scalar` is a token's index or `:value`, each of the three
//! left out at will. A spec of any other shape runs the library's text,
//! which says what it does with it.
//!
//! What a native must do is what the text does, pass for pass:
//!
//! - An open pass of a rule the spec names announces its `:key` first:
//! the string, or the `:val` of the pass's token at that index, nothing
//! when the pass consumed no such token.
//! - It then begins its `:container`, unless the rule it replaced carried
//! that container on (below), or yields its `:scalar` from the token at
//! that index, when the pass consumed one; `:value` yields nothing on an
//! open pass, and `:scalar` nothing for a container rule.
//! - A close pass of a container rule ends its container, unless the
//! pass's alternate replaces the rule with one the spec names a
//! container: then the container goes on, and the replacing rule's open
//! pass begins none. A close pass of any other rule yields its
//! `:scalar :value`, the pass's own value, when it has one.
//! - A pass of a rule the spec does not name yields nothing, and the end
//! of the passes inside a container is `PROTOCOL_ORDER_ERROR`.
//!
//! The library's failures are the native's, with their codes and texts: a
//! key whose token's value is not a string, and a scalar whose token's
//! value is a container, are `DSL_TYPE_ERROR`; a close with no container
//! open is the library's `pop` of an empty stack, `DSL_TYPE_ERROR` too.
use HashMap;
/// The container a rule's passes begin and end.
/// The member name a rule's open pass announces.
/// The scalar a rule yields.
/// What one rule's passes do: an entry of the spec.
/// A `transduce-tree` spec of the standard shape: the rules it names.