@@ -17,9 +17,6 @@ use mac::format_if;
17
17
use std:: borrow:: Cow :: Borrowed ;
18
18
use std:: char:: from_u32;
19
19
20
- use self :: State :: * ;
21
- pub ( super ) use self :: Status :: * ;
22
-
23
20
//§ tokenizing-character-references
24
21
pub ( super ) struct CharRef {
25
22
/// The resulting character(s)
@@ -64,7 +61,7 @@ impl CharRefTokenizer {
64
61
pub ( super ) fn new ( is_consumed_in_attribute : bool ) -> CharRefTokenizer {
65
62
CharRefTokenizer {
66
63
is_consumed_in_attribute,
67
- state : Begin ,
64
+ state : State :: Begin ,
68
65
result : None ,
69
66
num : 0 ,
70
67
num_too_big : false ,
@@ -99,15 +96,15 @@ impl CharRefTokenizer {
99
96
chars : [ '\0' , '\0' ] ,
100
97
num_chars : 0 ,
101
98
} ) ;
102
- Done
99
+ Status :: Done
103
100
}
104
101
105
102
fn finish_one ( & mut self , c : char ) -> Status {
106
103
self . result = Some ( CharRef {
107
104
chars : [ c, '\0' ] ,
108
105
num_chars : 1 ,
109
106
} ) ;
110
- Done
107
+ Status :: Done
111
108
}
112
109
}
113
110
@@ -118,17 +115,17 @@ impl CharRefTokenizer {
118
115
input : & BufferQueue ,
119
116
) -> Status {
120
117
if self . result . is_some ( ) {
121
- return Done ;
118
+ return Status :: Done ;
122
119
}
123
120
124
121
debug ! ( "char ref tokenizer stepping in state {:?}" , self . state) ;
125
122
match self . state {
126
- Begin => self . do_begin ( tokenizer, input) ,
127
- Octothorpe => self . do_octothorpe ( tokenizer, input) ,
128
- Numeric ( base) => self . do_numeric ( tokenizer, input, base) ,
129
- NumericSemicolon => self . do_numeric_semicolon ( tokenizer, input) ,
130
- Named => self . do_named ( tokenizer, input) ,
131
- BogusName => self . do_bogus_name ( tokenizer, input) ,
123
+ State :: Begin => self . do_begin ( tokenizer, input) ,
124
+ State :: Octothorpe => self . do_octothorpe ( tokenizer, input) ,
125
+ State :: Numeric ( base) => self . do_numeric ( tokenizer, input, base) ,
126
+ State :: NumericSemicolon => self . do_numeric_semicolon ( tokenizer, input) ,
127
+ State :: Named => self . do_named ( tokenizer, input) ,
128
+ State :: BogusName => self . do_bogus_name ( tokenizer, input) ,
132
129
}
133
130
}
134
131
@@ -139,17 +136,17 @@ impl CharRefTokenizer {
139
136
) -> Status {
140
137
match tokenizer. peek ( input) {
141
138
Some ( 'a' ..='z' | 'A' ..='Z' | '0' ..='9' ) => {
142
- self . state = Named ;
139
+ self . state = State :: Named ;
143
140
self . name_buf_opt = Some ( StrTendril :: new ( ) ) ;
144
- Progress
141
+ Status :: Progress
145
142
} ,
146
143
Some ( '#' ) => {
147
144
tokenizer. discard_char ( input) ;
148
- self . state = Octothorpe ;
149
- Progress
145
+ self . state = State :: Octothorpe ;
146
+ Status :: Progress
150
147
} ,
151
148
Some ( _) => self . finish_none ( ) ,
152
- None => Stuck ,
149
+ None => Status :: Stuck ,
153
150
}
154
151
}
155
152
@@ -162,15 +159,15 @@ impl CharRefTokenizer {
162
159
Some ( c @ ( 'x' | 'X' ) ) => {
163
160
tokenizer. discard_char ( input) ;
164
161
self . hex_marker = Some ( c) ;
165
- self . state = Numeric ( 16 ) ;
162
+ self . state = State :: Numeric ( 16 ) ;
166
163
} ,
167
164
Some ( _) => {
168
165
self . hex_marker = None ;
169
- self . state = Numeric ( 10 ) ;
166
+ self . state = State :: Numeric ( 10 ) ;
170
167
} ,
171
- None => return Stuck ,
168
+ None => return Status :: Stuck ,
172
169
}
173
- Progress
170
+ Status :: Progress
174
171
}
175
172
176
173
fn do_numeric < Sink : TokenSink > (
@@ -180,7 +177,7 @@ impl CharRefTokenizer {
180
177
base : u32 ,
181
178
) -> Status {
182
179
let Some ( c) = tokenizer. peek ( input) else {
183
- return Stuck ;
180
+ return Status :: Stuck ;
184
181
} ;
185
182
match c. to_digit ( base) {
186
183
Some ( n) => {
@@ -193,14 +190,14 @@ impl CharRefTokenizer {
193
190
}
194
191
self . num = self . num . wrapping_add ( n) ;
195
192
self . seen_digit = true ;
196
- Progress
193
+ Status :: Progress
197
194
} ,
198
195
199
196
None if !self . seen_digit => self . unconsume_numeric ( tokenizer, input) ,
200
197
201
198
None => {
202
- self . state = NumericSemicolon ;
203
- Progress
199
+ self . state = State :: NumericSemicolon ;
200
+ Status :: Progress
204
201
} ,
205
202
}
206
203
}
@@ -215,7 +212,7 @@ impl CharRefTokenizer {
215
212
Some ( _) => tokenizer. emit_error ( Borrowed (
216
213
"Semicolon missing after numeric character reference" ,
217
214
) ) ,
218
- None => return Stuck ,
215
+ None => return Status :: Stuck ,
219
216
} ;
220
217
self . finish_numeric ( tokenizer)
221
218
}
@@ -277,7 +274,7 @@ impl CharRefTokenizer {
277
274
// peek + discard skips over newline normalization, therefore making it easier to
278
275
// un-consume
279
276
let Some ( c) = tokenizer. peek ( input) else {
280
- return Stuck ;
277
+ return Status :: Stuck ;
281
278
} ;
282
279
tokenizer. discard_char ( input) ;
283
280
self . name_buf_mut ( ) . push_char ( c) ;
@@ -290,7 +287,7 @@ impl CharRefTokenizer {
290
287
self . name_len = self . name_buf ( ) . len ( ) ;
291
288
}
292
289
// Otherwise we just have a prefix match.
293
- Progress
290
+ Status :: Progress
294
291
} ,
295
292
296
293
// 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