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
//! The specials-scan interface: how the tokenizer asks the language (preset) whether a
//! callable-triggering character sequence starts at the current position.
//!
//! Specials trigger strings are the one part of tokenization that is *not* plain
//! [`TokenRules`](super::TokenRules) data: a language may have many trigger strings in
//! scope, and which ones they are changes as scopes are pushed and popped, so
//! recognizing them is delegated to a [`Lang`](crate::core::Lang) hook
//! (`Lang::scan_specials`) instead of being enumerated in the rules.
//!
//! Recognition and resolution happen in one call: a [`SpecialsMatch`] holds the
//! resolved spec, and the matched text *is* the name, so scanning and lookup cannot
//! disagree about normalization or scoping.
//!
//! [`TriggerChars`] keeps the hook off the hot path: it is the set of characters that may
//! start a specials trigger, reported by `Lang::specials_trigger_chars` and cached per
//! parsing state (rebuilt only at state transitions, like the
//! [`PrefixTable`](super::PrefixTable)). The hook is consulted only when the current
//! character is in the set.
use String;
use Arc;
use fmt;
use crateSpan;
use crateCallableSpec;
use crateLang;
use TokenErrorKind;
/// A successful specials scan: a callable trigger matched at the scanned position.
///
/// Returned by `Lang::scan_specials(state, content, pos)`, and by
/// [`scan_specials_trigger`](super::scan_specials_trigger), which calls that hook.
/// Positions are absolute byte offsets into `content` (not relative to the scanned tail),
/// so spans in errors and in the resulting token need no offset arithmetic.
/// An error that [`Lang::scan_specials`](crate::core::Lang::scan_specials) returns when it
/// fails to scan a specials trigger.
///
/// A specials scan error contains the condition that describes the error
/// ([`kind`](Self::kind)) and the byte range of the scanned content where the error
/// occurred ([`span`](Self::span)). The standard token reader converts it into a
/// [`TokenError`](super::TokenError) whose span lies in the source that the reader reads.
/// The hook receives only the parsing state, the content and the scan position, so it
/// cannot describe how to continue past the error. Therefore the token error has no
/// [`TokenRecovery`](super::TokenRecovery), and it stops the parse, also in a tolerant
/// parse.
///
/// [`scan_specials_trigger`](super::scan_specials_trigger) also returns a specials scan
/// error when the hook returns a match end or an error span that lies outside the scanned
/// content or not on a character boundary. Its condition is then an
/// [`ImplementationError`](crate::core::constructs::ImplementationError), and its span is
/// the empty range at the scan position.
///
/// To report a problem in the document that the parse can continue past, the hook returns
/// a [`SpecialsMatch`] whose spec has a parser that reports the problem.
/// The characters that may start a specials trigger in some parsing state.
///
/// A language reports it from `Lang::specials_trigger_chars(&StateData<L>)`; the parsing
/// state computes it once, when it is built, and caches it. Every scan of a specials
/// trigger is gated by it, so the scan hook runs only at characters that could start
/// one. A hook whose triggers cannot be summarized by their first characters (fully
/// dynamic recognition) returns [`TriggerChars::Any`] — correct, but it pays for the scan
/// at every character.