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
//! Construct parsers: the [`ConstructParser`] contract, and the standard parsers
//! and argument parsers written against it.
//!
//! Every construct is parsed by a [`ConstructParser`] implementation that reads
//! tokens and stages nodes through one [`ParseContext`]. The standard shapes ship
//! here: the root parse ([`RootNodesParser`], which the parse entry point runs
//! directly, above every descent), the content loop that dispatches on each token
//! ([`NodesParser`], with its stop conditions [`StopSpec`] and [`StopCause`]),
//! groups ([`GroupParser`], with the [`ChildStateSpec`] policy deciding the state a
//! child construct is parsed under), callable invocations
//! ([`StdInvocationParser`], which takes the resolved [`Invocation`] as its input),
//! environment bodies ([`EnvironmentBodyParser`]), and verbatim material
//! ([`VerbatimBodyParser`]).
//!
//! An argument is a parser too: [`ArgumentParser`] returns
//! [`ParsedArgumentNodes`], and the standard argument forms — delimited group,
//! optional group, chars group, literal marker, verbatim, embellishments, tack-on
//! fields — are shipped as ordinary parsers you configure with the group types and
//! rules they should use. Each parser's diagnostic conditions are documented next
//! to the parser that raises them.
//!
//! [Writing a construct parser](crate::guide::construct_parsers) introduces the job
//! from scratch, and [the parsing model](crate::guide::parsing_model) shows where
//! these parsers sit in a whole parse.
//!
//! Three contracts hold for everything in this module.
//!
//! # Temporaries and stored behavior
//!
//! Construct parsers are **temporaries**: each is constructed with its per-use
//! configuration where it is needed, keeps working state in its own fields
//! ([`ConstructParser::parse`] takes `&mut self`), may freely borrow, and is dropped
//! when its construct's parse ends. A construct parser is never stored in a spec.
//!
//! **Stored** behavior objects — specs and [`ArgumentParser`]s — are the opposite:
//! `Arc`-shared, immutable, `Send + Sync` by contract, and given every per-use input
//! as an argument. Closures (such as stop predicates) therefore belong to construct
//! parsers only; specs stay data.
//!
//! # State threading: the caller applies deltas
//!
//! [`ParseContext::state`] is the parser's **input** parsing state — the caller sets
//! it. A parser that parses child content under a modified state (a group interior,
//! an argument extent, a slot body) derives the child state and scopes it
//! structurally ([`ParseContext::with_parsing_state`] and its siblings): the outer
//! state is restored when the descent returns, because the caller still holds it.
//! The optional [`ParsingStateDelta`](crate::core::ParsingStateDelta) in
//! [`ConstructParser::parse`]'s return value is exclusively the construct's
//! **after-effect for the caller** (as with `\newcommand`, whose definition must
//! outlive the construct): the parser never applies it itself — deltas are plain
//! values, and the caller decides whether and where they apply.
//!
//! # Errors
//!
//! `Err` means **abort**: nobody continues past an `Err` from a construct parser.
//! Recovery from problems in the source happens *before* returning, at the
//! detection site — every detected problem is reported through
//! [`ParseContext::recover`], which applies the driver's recovery policy — and
//! abnormal endings of sub-parses travel as data ([`StopCause`]).
// Condition types stay next to the parser that raises them, with one deliberate
// exception: `InvalidSourceReferenceArgument` is defined beside the two conditions
// of `ParseContext::attach_source_reference` and raised by the include-like specs
// that read a source reference out of an argument, so that all three failures of an
// inclusion read the same wherever they come from.
pub use crate;
pub use crate;