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
//! The parsing machinery: what defines a language, the conditions a parse runs
//! under, and the engine that turns source text into a node tree.
//!
//! Most programs enter here through [`Language`]. A `Language` value pairs the
//! [`ParsingState`] that parses start from with a [`ParseDriver`], the object holding
//! a language's parse-time behavior; [`Language::parse`] then reads a string and
//! returns a [`ParseResult`] carrying the finished tree and the diagnostics recorded
//! along the way. If you only want to parse LaTeX-like input, take the ready-made
//! [`Latexlike`](crate::latexlike::Latexlike) language from the
//! [`latexlike`](crate::latexlike) preset and read
//! [Running the parser](crate::guide::parsing).
//!
//! # What a language is
//!
//! A language is a type implementing [`Lang`]. The trait fixes, at compile time, the
//! types a language parses with: the identifiers it uses for group classes and
//! callables, its modes, its tokenization, and the extra data it attaches to states,
//! nodes, and sessions. [`LangFeatures`] declares which syntactic features the
//! language has at all — groups, commands, comments, whitespace, and so on — so that a
//! language that has no comments pays nothing for them. [`TrivialLang`] supplies
//! defaults for every one of those choices, which is enough for tests and for
//! languages with no vocabularies of their own.
//!
//! # The parsing state
//!
//! A [`ParsingState`] is the complete set of conditions in force at one point of a
//! parse: the token rules currently in effect, the current mode, and the definitions
//! in scope. States are immutable and shared. To change one, describe the change as a
//! [`ParsingStateDelta`] — token-rule overrides, a mode switch, scope operations — and
//! derive a new state from it; the underlying data is [`StateData`]. Every node in a
//! finished tree records the state it was parsed under, so a fragment can later be
//! re-parsed under exactly the same conditions.
//!
//! # The engine
//!
//! One parse runs as follows. [`Language::parse`] (or the configurable
//! [`parse_setup`](Language::parse_setup) form) creates a [`ParserSession`], which
//! accumulates everything that one parse produces: the nodes being staged, the
//! diagnostics, and a stack of [`Frame`]s recording which constructs are currently
//! open, so that a reported problem can name the enclosing group or macro. Construct
//! parsers from [`constructs`] then read tokens and stage nodes, calling one another
//! for nested constructs; [`StdDescentGuard`] caps how deep that nesting may go.
//! Finally the session freezes into the [`ParseResult`].
//!
//! Customization happens on the driver: implementing [`ParseDriver`] is how a language
//! resolves command names, chooses whether a problem aborts the parse or is recorded
//! and tolerated, and substitutes parsers of its own. Every method has a default, and
//! [`StdParseDriver`] is a ready-made implementation configured with a recovery policy
//! and a command resolver. [Defining a language](crate::guide::custom_lang) covers
//! this end of the API.
//!
//! # The four submodules
//!
//! - [`token`] — turning source text into tokens: the
//! [`TokenRules`](token::TokenRules) that say what counts as a group delimiter, a
//! command, or a comment; the [`TokenReader`](token::TokenReader) that produces
//! tokens from those rules; and the token errors.
//! - [`specs`] — defining what a callable does: the specs that describe a macro or an
//! environment and the arguments it takes, and the providers, packages, and scopes
//! that hold those definitions and resolve a name to one.
//! - [`constructs`] — parsing one construct at a time: the [`ConstructParser`]
//! contract, the standard parsers the engine uses for content, groups, and
//! invocations, and the conditions they report.
//! - [`node`] — the node tree: reading it, its per-kind payloads, and building one
//! directly.
//!
//! The data models a parse produces are at the crate root — [`source`](crate::source)
//! for source text and positions, [`error`](crate::error) for diagnostics — together
//! with the tools that consume a finished tree, such as [`extract`](crate::extract).
//!
//! [`ConstructParser`]: constructs::ConstructParser
pub use crate;
pub use crateFrameRole;
pub use crate;