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
//! Token types for the CSS Syntax tokenizer.
//!
//! Implements the token definitions of CSS Syntax Module Level 3 §4.1
//! (Token Railroad Diagrams) and §5.2 (CSS Parsing Results).
//!
//! Every token type enumerated in §4.1 has a corresponding variant in
//! [`Token`]. The compiler enforces exhaustive `match` arms, so no token
//! kind can be forgotten by the parser.
use fmt;
/// A CSS token (§4.1).
///
/// Variants correspond to the token types defined by the CSS Syntax
/// Module §4.1 railroad diagrams. Each variant's doc comment cites the
/// relevant normative section.
/// The type flag on a `<hash-token>` (§4.1, §4.3.4).
///
/// Per §4.3.4, when consuming an ident-like token starting with `#`:
/// - If the following code points would start an ident sequence (§4.3.9),
/// the hash type is "id".
/// - Otherwise, if the following code points are hex digits, the hash
/// type is "unrestricted".
/// - Otherwise (no ident sequence, no hex digits), the hash is still
/// "unrestricted" with an empty value.
/// A numeric value carried by `<number-token>`, `<percentage-token>`,
/// and `<dimension-token>` (§4.3.13).
///
/// Per §4.3.13 "Consume a number", the numeric value is parsed as either
/// an integer or a floating-point value, and a flag records which kind
/// was found. The sign is included in the value.
/// The current state of the CSS tokenizer.
///
/// Unlike the HTML tokenizer (which has ~80 explicit states per WHATWG
/// §13.2.5), the CSS tokenizer is a recursive-descent algorithm: the
/// main entry point `consume_a_token` (§4.3.1) dispatches to
/// sub-algorithms without a persistent state machine. [`State`] is
/// therefore minimal — it only tracks the top-level position (consuming
/// tokens vs. EOF emitted) for the [`Tokenizer::next_token`] iterator
/// protocol.