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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
//! # techy
//!
//! A fast, extensible parser toolkit for LaTeX-like markup languages.
//!
//! techy reads marked-up source text — LaTeX itself, or any language built from similar
//! ingredients — and produces a *node tree*: an Abstract Syntax Tree (AST) your program
//! can analyze, transform, or convert to another format. The parsing engine has no
//! built-in LaTeX behavior; the familiar meaning of `\`, `{`, `}`, `%`, math modes, and
//! environments comes from the [`latexlike`] preset, which is built entirely from the
//! same public extension points you would use to define a language of your own.
//!
//! ## Quick start
//!
//! Parse a document with the `latexlike` preset and read what came out. Definitions are
//! supplied by the embedder — techy ships no LaTeX definitions database — so the example
//! first registers the one macro it uses.
//!
//! ```rust
//! use techy::core::specs::Package;
//! use techy::core::{Language, ParsingState};
//! use techy::error::Recovery;
//! use techy::latexlike::{Latexlike, LatexlikeDriver};
//!
//! // `\cite` takes an optional `[…]` argument, then a mandatory `{…}` one.
//! let mut package: Package<Latexlike> = Package::new("mydefs");
//! package.define_macro("cite", ["o", "m"]).unwrap();
//!
//! let language: Language<Latexlike> = Language::new(
//! LatexlikeDriver::new(Recovery::Strict),
//! ParsingState::lang_initial_with_packages([package]).expect("seed state"),
//! );
//! let result = language.parse(r"see \cite[Lemma 3]{Author}!").unwrap();
//!
//! // The root node lists the top-level content; its second child is the invocation.
//! let cite = result.tree.root().child(1).unwrap();
//! assert_eq!(cite.macro_name(), Some("cite"));
//! assert_eq!(cite.span_content(), r"\cite[Lemma 3]{Author}");
//!
//! // Each argument records whether it was provided and where its content nodes are.
//! let author = cite.argument_content_nodes(1).unwrap();
//! assert_eq!(author.source_text(), Some("Author"));
//! ```
//!
//! ## Where to go next
//!
//! New to techy? The [`guide`] is the narrative documentation; the modules listed below
//! are the API reference. [Learn techy by example](guide::learn_by_example) covers
//! parsing, definitions, and the tree-consumer tools in one page, and
//! [Introduction](guide::introduction) explains what the library is for and how the
//! documentation is organized.
//!
//! ## The public modules
//!
//! Every item has exactly one canonical public path, placed by role: the data models
//! and the tree-consumer tools at the top level, the parsing machinery in [`core`], and
//! the ready-made language in [`latexlike`].
//!
//! - [`source`] — the source model: source content, plain byte ranges
//! ([`Span`](source::Span)), ranges that also name their source
//! ([`SourceSpan`](source::SourceSpan)), the provenance of included content,
//! pluggable source resolution, and line/column analysis computed on demand.
//! - [`error`] — structured diagnostics tied to source spans, and the policy that
//! decides whether a parse stops at the first problem or recovers and continues.
//! - [`extract`] — helpers that pull content out of a parsed node tree, such as
//! splitting a node run at chosen characters or reading a key/value list.
//! - [`visit`] — read-only traversal of a node tree:
//! [`TreeWalker`](visit::TreeWalker) drives a [`NodeVisitor`](visit::NodeVisitor),
//! which is called on entering and on leaving each node and controls where the walk
//! goes next.
//! - [`transform`] — tree-to-tree transformation:
//! [`TreeRestager`](transform::TreeRestager) reads an existing tree and asks a
//! [`RestageVisitor`](transform::RestageVisitor), node by node, what the new tree
//! should contain.
//! - [`recompose`] — tree-to-value recomposition: a
//! [`Recomposer`](recompose::Recomposer) returns one instruction per node — emit this
//! value, or combine the children's values — and
//! [`TreeRecomposer`](recompose::TreeRecomposer) combines them into a single result.
//! Re-emitting the original source is one such recomposer, the preset's
//! [`source_recomposer`](latexlike::source_recomposer).
//! - [`serialize`] — serialization to and from a format-independent value model
//! ([`SerialValue`](serialize::SerialValue)). Types opt in through the write and read
//! traits — [`SerializableObject`](serialize::SerializableObject) and
//! [`DeserializableObject`](serialize::DeserializableObject) for objects stored in a
//! table, [`SerializableValue`](serialize::SerializableValue) and
//! [`DeserializableValue`](serialize::DeserializableValue) for values embedded in
//! place — and a language declares its participation with
//! [`SerializableLang`](serialize::SerializableLang). A
//! [`SerdeSession`](serialize::SerdeSession) holds the standard tables of sources,
//! parsing states, specs, providers, trees, diagnostics, and parse results.
//! - [`core`] — the parsing machinery: the `Lang` contract that defines a language, the
//! parsing state, and the parse engine ([`Language`](core::Language) and its
//! `parse()`, producing a [`ParseResult`](core::ParseResult)). It has four
//! submodules:
//! - [`core::token`] — tokenization: a language declares its tokenization as one
//! type, which names the token types, the [`TokenReader`](core::token::TokenReader)
//! trait and the standard reader, the [`TokenRules`](core::token::TokenRules) data,
//! and the token errors.
//! - [`core::specs`] — defining callables: the specs that describe a macro,
//! environment, or specials; the providers and packages that hold them; and the
//! scopes that resolve a name to a spec.
//! - [`core::constructs`] — parsing individual constructs: the
//! [`ConstructParser`](core::constructs::ConstructParser) contract, the standard
//! parsers, and the conditions they report.
//! - [`core::node`] — the flat, immutable node tree: reading it, its per-kind
//! payloads, and building one.
//! - [`latexlike`] — the ready-made LaTeX-like language: the
//! [`Latexlike`](latexlike::Latexlike) language with text and math modes, command
//! resolution through a stack of scopes, the default token rules and base specials,
//! environments (`\begin`/`\end`), verbatim content, and convenience accessors on
//! node references for the preset's own constructs. Every preset item is namespaced
//! under `techy::latexlike`.
//!
//! ## Dependencies, features, and the panic policy
//!
//! **no_std and alloc.** The crate depends on `core` and `alloc` only. Several objects
//! are shared as `Arc`, so the target must support atomics. The crate performs no
//! input/output of its own: content lookup (for `\input`, if the language declares it)
//! is delegated to traits the embedder implements. It therefore builds for WebAssembly
//! targets such as `wasm32-unknown-unknown`, where the host supplies all input.
//!
//! **Minimal dependencies.** The crate pulls in as few runtime dependencies as
//! possible: currently only `hashbrown`, plus `serde` when that feature is enabled.
//! A few build-time dependencies implement the derive macros.
//!
//! **The panic policy.** This library is designed never to panic on document
//! input. A small set of public methods and functions may panic on a caller
//! contract violation, following standard Rust patterns such as unguarded index
//! accessors; the guide chapter [Panics](guide::panics) is the complete list of
//! public items that can panic.
//!
//! **Cargo features.**
//! - `serde` (off by default) — renders techy's serialized values (node trees, for
//! instance) through [serde](https://serde.rs). See [`serialize`] and the guide
//! chapter [Serialization](guide::serialize).
// no_std-friendly, alloc-only ([§dd-dr:dependencies]); tests build with std for convenience.
extern crate alloc;
// The `techy-derive` macros emit `::techy::__private::…` paths so that generated code
// resolves in downstream crates; this self-alias makes those paths resolve inside techy
// itself.
extern crate self as techy;
// Internal topic modules: private organization, permanently invisible to public paths.
// The public API is exported exclusively through the facade modules below
// ([§dd-dr:public-namespace-topology] — one canonical public path per item).
pub
pub
pub
pub
pub
pub
pub
// The public facades. `source`, `error`, and `serialize` are their own facades (their
// submodules are private); `extract`, `transform`, `visit`, `recompose`, and
// `latexlike` are ordinary public modules.
// Narrative documentation: markdown pages in the workspace-level `docs/` rendered as
// doc-only modules. `cfg(doc)` keeps them out of compiled code; rustdoc (including
// doctest collection) builds with `--cfg doc`, so code blocks in these pages still run
// as doctests. The docs sidebar pins these pages in a "Guide" section
// (docs/rustdoc-header.html, wired up in .cargo/config.toml); new chapters must also be
// added to GUIDE_PAGES there.
/// Support module for generated code only. Not public API.
///
/// It re-exports everything the expansions of `techy-derive`'s derives and of the
/// `serial_index!` macro refer to: `alloc` paths spelled so they resolve from both `std`
/// and `no_std` consumer crates; the diagnostics items the condition derives implement
/// and construct; the contexts, errors, and field and variant helpers the value derives'
/// generated bodies use; and the wire conversion traits and helpers a typed table
/// position implements.
///
/// The derives and the macro emit only `::techy::__private::…` / `$crate::__private::…`
/// paths, as serde does, so the public module topology never constrains, and is never
/// constrained by, generated output.
/// The version of the `techy` Cargo package (`CARGO_PKG_VERSION`); always a valid
/// [semver](https://semver.org/) string.
pub const VERSION: &str = env!;