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
//! Tokenization: the token types, the token reader, the token rules, and the scan
//! helpers behind them.
//!
//! Tokenizing turns source text into **tokens**: minimal, opaque values that each name
//! one thing to parse next — one character, a group delimiter, a command, a specials
//! trigger, a whole comment, a paragraph break, or the end of the input. Nothing is read
//! off a token directly: a construct parser holds tokens and passes them back to the
//! [`TokenReader`] that produced them, asking what a token *is*
//! ([`TokenReader::token_kind`], answered as a [`TokenKind`] view) and where it is
//! ([`TokenReader::source_span_of`], and the spans and stream positions taken at a
//! [`TokenEdge`]).
//!
//! The types, in the order a reader meets them:
//!
//! - [`Tokenization`] is how a language declares its tokenization — as one bundle, named
//! as [`Lang::Tokenization`](crate::core::Lang::Tokenization): the token type, the type
//! naming a place in the token stream, and how the reader for one parse is built.
//! Elsewhere those two types are spelled [`Token<L>`](Token) and
//! [`StreamPosition<L>`](StreamPosition). [`StdTokenization`] is the standard bundle:
//! [`StdToken`], [`StdStreamPosition`], [`StdTokenReader`].
//! - [`TokenKind`] is the parser-facing view of a token: the closed set of what a token
//! can be, with the spellings the reader matched.
//! - [`TokenReader`] is the trait every reader implements and the parser side calls.
//! [`StdTokenReader`] is the standard implementation; it recognizes constructs by
//! composing the scan helpers ([`skip_whitespace`], [`scan_paragraph_break`],
//! [`scan_group_delimiter`], [`command_rule_at`], [`scan_command`], [`scan_comment`],
//! [`scan_specials_trigger`]), free functions a reader of one's own may compose
//! differently.
//! - [`TokenRules`] is the data a reader works from — which characters are whitespace,
//! which delimiters open groups, which characters start commands and comments. It is
//! held in the parsing state, so it can change mid-parse; [`PrefixTable`] and
//! [`TriggerChars`] are the caches derived from it for the two lookups that run at
//! every position.
//! - [`TokenError`] reports a condition met while reading, optionally with a
//! [`TokenRecovery`]: a placeholder token and the stream position to resume at.
//! Whether a parse stops there or continues with the placeholder is decided by the
//! session's [`Recovery`](crate::error::Recovery) policy, not by the reader.
//!
//! Four properties of this token model shape the parsers written against it:
//!
//! - A [`Char`](TokenKind::Char) token covers exactly one character. Consecutive
//! characters are joined into a single node later, so a parser that must read
//! character by character (a tabular preamble, say) can.
//! - A command token says only that a name was written after an escape character, not
//! what that name means: `\begin` is a [`Command`](TokenKind::Command) token like
//! `\foobar`, and which names are macros, environments, or anything else is decided at
//! parse time. [`Specials`](TokenKind::Specials) is the exception — recognizing a
//! trigger there is already resolving it, so the token holds the spec it matched.
//! - Whitespace before a token (its *pre-space*) is content and reaches the node tree;
//! whitespace a command or a comment absorbs after itself (its *post-space*) is syntax
//! and does not. [`skip_whitespace`] applies the paragraph rule to both: skipped
//! whitespace never consumes a newline that belongs to a paragraph break.
//! - Every stream ends with a terminal [`EndOfStream`](TokenKind::EndOfStream) token
//! whose pre-space carries the input's final whitespace, so reading a token never
//! answers an `Option`.
//!
//! [Language syntax](crate::guide::language_syntax) describes the constructs these
//! tokens stand for, [Tokens and token
//! rules](crate::guide::concepts_overview#tokens-and-token-rules) places them in the
//! parsing model, and [Defining a custom
//! language](crate::guide::custom_lang#token-rules-and-specials-recognition) covers
//! writing rules and specials recognition for a language of one's own.
// The submodule sharing the parent's name is deliberate: the token is this topic's
// anchor type, and the submodule is private (everything is re-exported here).
pub use ;
// Internal test infrastructure, not public API (decided July 2026, Action-02
// follow-up): its role is the lockstep reader-agreement harness of the construct-parser
// test suites, and its fixed-list fidelity gap (no re-tokenization under the peek
// state) makes it unfit as a public reader contract.
pub use TokenListReader;
pub use ;
pub use ;
// Internal test infrastructure, not public API (like `TokenListReader` above): the
// scripted multi-source reader, its tokenization types, and the test language that
// declares them. It serves one parse from several sources, which is what a language
// with `Lang::OBEYS_SPAN_TILING = false` allows and nothing else in the crate does.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;