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
139
140
141
142
143
144
145
146
//! Content pointers: synthesized nodes that show content written elsewhere in
//! the tree, without copying it.
//!
//! A **content pointer** ([`ContentPointer`]) is the payload of a synthesized
//! node that shows, where the node is placed, content written elsewhere in
//! the tree (an xnote's content in the list of xnotes, a term in its
//! definition's lead-in, a theorem's title) without copying it: the address of
//! the node the content belongs to, and the node region of that node that
//! holds it (one of its arguments or slots; [`NodeRegion`]). See [content
//! pointers](crate::guide::concepts_overview#content-pointers).
//!
//! A feature that needs one builds a node of an element of its own carrying a
//! `ContentPointer`, and that element's lowering rule calls
//! [`lower_content_pointer`]. The function lowers the pointed region where the
//! pointer is placed, through [`Lowerer::lower_region`], as content of the
//! tree that holds it: a numbered list inside it is numbered as the document
//! numbered it, a labeled equation is an ordinary labeled reference point.
//! The content is lowered once, where the pointer is placed, provided the
//! feature lowers that region nowhere else.
//!
//! The feature that owns the pointer's element supplies a check
//! ([`PointerCheck`]) that the node a pointer refers to is one whose region
//! that element may show, because content shown both through a pointer and in
//! its own place would appear twice. Where the check fails, it reports a
//! condition of the feature's own.
use ;
use SerialValue;
use crate;
use crate;
use crateNodeAddr;
use RegionNotFound;
/// The payload of a content pointer: the node some content belongs to, and
/// the node region of that node that holds the content, which the pointer
/// shows where it is placed. A feature's own synthesized element carries it
/// (see the [module documentation](self)).
///
/// The node is identified by its address, which is valid only within the
/// run that built the pointer: the address of a node of a document tree, or
/// of a node of a synthesized value the lowering holds (see
/// [`Lowerer::lower_region`]). A pointer stored in a table must refer to a
/// node of a document tree: a synthesized value's identifier is valid only
/// inside the stage call that brought the value up to date, and the runner
/// adds a table to the run's store after that call has ended.
///
/// Its projection is `{target: "<tree>/<node index>", region: "argument
/// <i>"}` (or `"slot <i>"`). No payload reader is registered for it, so a
/// tree holding a pointer can be printed but not read back.
/// The check a feature supplies to [`lower_content_pointer`]. It receives the
/// [`Lowerer`], the node a pointer refers to and the node region the pointer
/// gives, and returns whether the pointer's element may show that region of
/// that node. When it returns `false`, it must already have reported the
/// refusal (a condition of the feature's own, at the pointer); the pointer
/// then writes nothing.
///
/// # Errors
///
/// A [`LowerError`] the check returns ends the pointer's lowering with that
/// error, for example a table read the calling rule did not declare.
pub type PointerCheck<'f> =
dyn FnMut + 'f;
/// Lowers the content that the node `pointer` refers to through its
/// [`ContentPointer`] payload, where `pointer` is placed. Every lowering rule
/// of an element whose nodes carry a content pointer calls this function.
///
/// The function looks up, through [`Lowerer::lower_region`], the node and
/// the region the pointer refers to, and calls `check` with them; if `check`
/// refuses them, the pointer writes nothing. Otherwise the region's content
/// is lowered and arranged by `shape` ([`RegionShape`]; the plain shape is
/// [`lower_region_content`](super::lower_region_content)), and the staged
/// nodes are returned.
///
/// A pointer to a node the lowering cannot reach, or to a region that node
/// does not have, is reported at the pointer as
/// `flm.lowering.region-not-found` ([`RegionNotFound`], with the pointer's
/// element) and writes nothing either; the content around the pointer is
/// still written.
///
/// # Errors
///
/// [`LowerError`] when `pointer` carries no [`ContentPointer`], and any error
/// `check` or `shape` returns.