Skip to content

Commit ae80bf7

Browse files
committed
Rework use of lookahead_and_consume! to avoid mut borrows in pattern guards
1 parent 809d606 commit ae80bf7

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/tokenizer/mod.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,17 +1068,19 @@ impl<'sink, Sink: TokenSink> Tokenizer<'sink, Sink> {
10681068
}},
10691069

10701070
//§ after-doctype-name-state
1071-
states::AfterDoctypeName => loop { match () {
1072-
_ if lookahead_and_consume!(self, 6, |s| s.eq_ignore_ascii_case("public"))
1073-
=> go!(self: to AfterDoctypeKeyword Public),
1074-
_ if lookahead_and_consume!(self, 6, |s| s.eq_ignore_ascii_case("system"))
1075-
=> go!(self: to AfterDoctypeKeyword System),
1076-
_ => match get_char!(self) {
1077-
'\t' | '\n' | '\x0C' | ' ' => (),
1078-
'>' => go!(self: emit_doctype; to Data),
1079-
_ => go!(self: error; force_quirks; to BogusDoctype),
1080-
},
1081-
}},
1071+
states::AfterDoctypeName => loop {
1072+
if lookahead_and_consume!(self, 6, |s| s.eq_ignore_ascii_case("public")) {
1073+
go!(self: to AfterDoctypeKeyword Public);
1074+
} else if lookahead_and_consume!(self, 6, |s| s.eq_ignore_ascii_case("system")) {
1075+
go!(self: to AfterDoctypeKeyword System);
1076+
} else {
1077+
match get_char!(self) {
1078+
'\t' | '\n' | '\x0C' | ' ' => (),
1079+
'>' => go!(self: emit_doctype; to Data),
1080+
_ => go!(self: error; force_quirks; to BogusDoctype),
1081+
}
1082+
}
1083+
},
10821084

10831085
//§ after-doctype-public-keyword-state after-doctype-system-keyword-state
10841086
states::AfterDoctypeKeyword(kind) => loop { match get_char!(self) {
@@ -1155,15 +1157,17 @@ impl<'sink, Sink: TokenSink> Tokenizer<'sink, Sink> {
11551157
}},
11561158

11571159
//§ markup-declaration-open-state
1158-
states::MarkupDeclarationOpen => loop { match () {
1159-
_ if lookahead_and_consume!(self, 2, |s| s == "--")
1160-
=> go!(self: clear_comment; to CommentStart),
1161-
_ if lookahead_and_consume!(self, 7, |s| s.eq_ignore_ascii_case("doctype"))
1162-
=> go!(self: to Doctype),
1163-
// FIXME: CDATA, requires "adjusted current node" from tree builder
1164-
// FIXME: 'error' gives wrong message
1165-
_ => go!(self: error; to BogusComment),
1166-
}},
1160+
states::MarkupDeclarationOpen => loop {
1161+
if lookahead_and_consume!(self, 2, |s| s == "--") {
1162+
go!(self: clear_comment; to CommentStart);
1163+
} else if lookahead_and_consume!(self, 7, |s| s.eq_ignore_ascii_case("doctype")) {
1164+
go!(self: to Doctype);
1165+
} else {
1166+
// FIXME: CDATA, requires "adjusted current node" from tree builder
1167+
// FIXME: 'error' gives wrong message
1168+
go!(self: error; to BogusComment);
1169+
}
1170+
},
11671171

11681172
//§ cdata-section-state
11691173
states::CdataSection

0 commit comments

Comments
 (0)