@@ -16,9 +16,6 @@ use log::debug;
16
16
use std:: borrow:: Cow :: { self , Borrowed } ;
17
17
use std:: char:: from_u32;
18
18
19
- use self :: State :: * ;
20
- pub ( super ) use self :: Status :: * ;
21
-
22
19
//§ tokenizing-character-references
23
20
pub ( super ) struct CharRef {
24
21
/// The resulting character(s)
@@ -63,7 +60,7 @@ impl CharRefTokenizer {
63
60
pub ( super ) fn new ( is_consumed_in_attribute : bool ) -> CharRefTokenizer {
64
61
CharRefTokenizer {
65
62
is_consumed_in_attribute,
66
- state : Begin ,
63
+ state : State :: Begin ,
67
64
result : None ,
68
65
num : 0 ,
69
66
num_too_big : false ,
@@ -98,15 +95,15 @@ impl CharRefTokenizer {
98
95
chars : [ '\0' , '\0' ] ,
99
96
num_chars : 0 ,
100
97
} ) ;
101
- Done
98
+ Status :: Done
102
99
}
103
100
104
101
fn finish_one ( & mut self , c : char ) -> Status {
105
102
self . result = Some ( CharRef {
106
103
chars : [ c, '\0' ] ,
107
104
num_chars : 1 ,
108
105
} ) ;
109
- Done
106
+ Status :: Done
110
107
}
111
108
}
112
109
@@ -117,17 +114,17 @@ impl CharRefTokenizer {
117
114
input : & BufferQueue ,
118
115
) -> Status {
119
116
if self . result . is_some ( ) {
120
- return Done ;
117
+ return Status :: Done ;
121
118
}
122
119
123
120
debug ! ( "char ref tokenizer stepping in state {:?}" , self . state) ;
124
121
match self . state {
125
- Begin => self . do_begin ( tokenizer, input) ,
126
- Octothorpe => self . do_octothorpe ( tokenizer, input) ,
127
- Numeric ( base) => self . do_numeric ( tokenizer, input, base) ,
128
- NumericSemicolon => self . do_numeric_semicolon ( tokenizer, input) ,
129
- Named => self . do_named ( tokenizer, input) ,
130
- BogusName => self . do_bogus_name ( tokenizer, input) ,
122
+ State :: Begin => self . do_begin ( tokenizer, input) ,
123
+ State :: Octothorpe => self . do_octothorpe ( tokenizer, input) ,
124
+ State :: Numeric ( base) => self . do_numeric ( tokenizer, input, base) ,
125
+ State :: NumericSemicolon => self . do_numeric_semicolon ( tokenizer, input) ,
126
+ State :: Named => self . do_named ( tokenizer, input) ,
127
+ State :: BogusName => self . do_bogus_name ( tokenizer, input) ,
131
128
}
132
129
}
133
130
@@ -138,17 +135,17 @@ impl CharRefTokenizer {
138
135
) -> Status {
139
136
match tokenizer. peek ( input) {
140
137
Some ( 'a' ..='z' | 'A' ..='Z' | '0' ..='9' ) => {
141
- self . state = Named ;
138
+ self . state = State :: Named ;
142
139
self . name_buf_opt = Some ( StrTendril :: new ( ) ) ;
143
- Progress
140
+ Status :: Progress
144
141
} ,
145
142
Some ( '#' ) => {
146
143
tokenizer. discard_char ( input) ;
147
- self . state = Octothorpe ;
148
- Progress
144
+ self . state = State :: Octothorpe ;
145
+ Status :: Progress
149
146
} ,
150
147
Some ( _) => self . finish_none ( ) ,
151
- None => Stuck ,
148
+ None => Status :: Stuck ,
152
149
}
153
150
}
154
151
@@ -161,15 +158,15 @@ impl CharRefTokenizer {
161
158
Some ( c @ ( 'x' | 'X' ) ) => {
162
159
tokenizer. discard_char ( input) ;
163
160
self . hex_marker = Some ( c) ;
164
- self . state = Numeric ( 16 ) ;
161
+ self . state = State :: Numeric ( 16 ) ;
165
162
} ,
166
163
Some ( _) => {
167
164
self . hex_marker = None ;
168
- self . state = Numeric ( 10 ) ;
165
+ self . state = State :: Numeric ( 10 ) ;
169
166
} ,
170
- None => return Stuck ,
167
+ None => return Status :: Stuck ,
171
168
}
172
- Progress
169
+ Status :: Progress
173
170
}
174
171
175
172
fn do_numeric < Sink : TokenSink > (
@@ -179,7 +176,7 @@ impl CharRefTokenizer {
179
176
base : u32 ,
180
177
) -> Status {
181
178
let Some ( c) = tokenizer. peek ( input) else {
182
- return Stuck ;
179
+ return Status :: Stuck ;
183
180
} ;
184
181
match c. to_digit ( base) {
185
182
Some ( n) => {
@@ -192,14 +189,14 @@ impl CharRefTokenizer {
192
189
}
193
190
self . num = self . num . wrapping_add ( n) ;
194
191
self . seen_digit = true ;
195
- Progress
192
+ Status :: Progress
196
193
} ,
197
194
198
195
None if !self . seen_digit => self . unconsume_numeric ( tokenizer, input) ,
199
196
200
197
None => {
201
- self . state = NumericSemicolon ;
202
- Progress
198
+ self . state = State :: NumericSemicolon ;
199
+ Status :: Progress
203
200
} ,
204
201
}
205
202
}
@@ -214,7 +211,7 @@ impl CharRefTokenizer {
214
211
Some ( _) => tokenizer. emit_error ( Borrowed (
215
212
"Semicolon missing after numeric character reference" ,
216
213
) ) ,
217
- None => return Stuck ,
214
+ None => return Status :: Stuck ,
218
215
} ;
219
216
self . finish_numeric ( tokenizer)
220
217
}
@@ -278,7 +275,7 @@ impl CharRefTokenizer {
278
275
// peek + discard skips over newline normalization, therefore making it easier to
279
276
// un-consume
280
277
let Some ( c) = tokenizer. peek ( input) else {
281
- return Stuck ;
278
+ return Status :: Stuck ;
282
279
} ;
283
280
tokenizer. discard_char ( input) ;
284
281
self . name_buf_mut ( ) . push_char ( c) ;
@@ -291,7 +288,7 @@ impl CharRefTokenizer {
291
288
self . name_len = self . name_buf ( ) . len ( ) ;
292
289
}
293
290
// Otherwise we just have a prefix match.
294
- Progress
291
+ Status :: Progress
295
292
} ,
296
293
297
294
// Can't continue the match.
@@ -324,8 +321,8 @@ impl CharRefTokenizer {
324
321
Some ( c) if c. is_ascii_alphanumeric ( ) => {
325
322
// Keep looking for a semicolon, to determine whether
326
323
// we emit a parse error.
327
- self . state = BogusName ;
328
- return Progress ;
324
+ self . state = State :: BogusName ;
325
+ return Status :: Progress ;
329
326
} ,
330
327
331
328
// Check length because &; is not a parse error.
@@ -390,7 +387,7 @@ impl CharRefTokenizer {
390
387
chars : [ from_u32 ( c1) . unwrap ( ) , from_u32 ( c2) . unwrap ( ) ] ,
391
388
num_chars : if c2 == 0 { 1 } else { 2 } ,
392
389
} ) ;
393
- Done
390
+ Status :: Done
394
391
}
395
392
} ,
396
393
}
@@ -404,12 +401,12 @@ impl CharRefTokenizer {
404
401
// peek + discard skips over newline normalization, therefore making it easier to
405
402
// un-consume
406
403
let Some ( c) = tokenizer. peek ( input) else {
407
- return Stuck ;
404
+ return Status :: Stuck ;
408
405
} ;
409
406
tokenizer. discard_char ( input) ;
410
407
self . name_buf_mut ( ) . push_char ( c) ;
411
408
match c {
412
- _ if c. is_ascii_alphanumeric ( ) => return Progress ,
409
+ _ if c. is_ascii_alphanumeric ( ) => return Status :: Progress ,
413
410
';' => self . emit_name_error ( tokenizer) ,
414
411
_ => ( ) ,
415
412
}
@@ -424,23 +421,20 @@ impl CharRefTokenizer {
424
421
) {
425
422
while self . result . is_none ( ) {
426
423
match self . state {
427
- Begin => drop ( self . finish_none ( ) ) ,
428
-
429
- Numeric ( _ ) if ! self . seen_digit => drop ( self . unconsume_numeric ( tokenizer, input) ) ,
430
-
431
- Numeric ( _) | NumericSemicolon => {
424
+ State :: Begin => drop ( self . finish_none ( ) ) ,
425
+ State :: Numeric ( _ ) if ! self . seen_digit => {
426
+ self . unconsume_numeric ( tokenizer, input) ;
427
+ } ,
428
+ State :: Numeric ( _) | State :: NumericSemicolon => {
432
429
tokenizer. emit_error ( Borrowed ( "EOF in numeric character reference" ) ) ;
433
430
self . finish_numeric ( tokenizer) ;
434
431
} ,
435
-
436
- Named => drop ( self . finish_named ( tokenizer, input, None ) ) ,
437
-
438
- BogusName => {
432
+ State :: Named => drop ( self . finish_named ( tokenizer, input, None ) ) ,
433
+ State :: BogusName => {
439
434
self . unconsume_name ( input) ;
440
435
self . finish_none ( ) ;
441
436
} ,
442
-
443
- Octothorpe => {
437
+ State :: Octothorpe => {
444
438
input. push_front ( StrTendril :: from_slice ( "#" ) ) ;
445
439
tokenizer. emit_error ( Borrowed ( "EOF after '#' in character reference" ) ) ;
446
440
self . finish_none ( ) ;
0 commit comments