Skip to content

Commit ddf916a

Browse files
committed
Cleanup
Signed-off-by: Nico Burns <[email protected]>
1 parent a8858a4 commit ddf916a

File tree

1 file changed

+31
-105
lines changed

1 file changed

+31
-105
lines changed

html5ever/src/tree_builder/rules.rs

Lines changed: 31 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -36,112 +36,54 @@ fn current_node<Handle>(open_elems: &[Handle]) -> &Handle {
3636
open_elems.last().expect("no current element")
3737
}
3838

39+
#[rustfmt::skip]
3940
macro_rules! tag {
4041
// Any start tag
4142
(<>) => {
42-
crate::tokenizer::Tag {
43-
kind: crate::tokenizer::StartTag,
44-
..
45-
}
46-
};
47-
48-
// Any end tag
49-
(</>) => {
50-
crate::tokenizer::Tag {
51-
kind: crate::tokenizer::EndTag,
52-
..
53-
}
54-
};
55-
56-
// Named end tag
57-
(<$tag:tt>) => {
58-
crate::tokenizer::Tag {
59-
kind: crate::tokenizer::StartTag,
60-
name: local_name!($tag),
61-
..
62-
}
63-
};
64-
65-
// Named start tag
66-
(</$tag:tt>) => {
67-
crate::tokenizer::Tag {
68-
kind: crate::tokenizer::EndTag,
69-
name: local_name!($tag),
70-
..
71-
}
72-
};
73-
}
74-
75-
macro_rules! tags {
76-
// Any start tag
77-
(<>) => {
78-
tag!(<>)
43+
crate::tokenizer::Tag { kind: crate::tokenizer::StartTag, .. }
7944
};
8045
(<>|$($tail:tt)*) => {
81-
tag!(<>) | tags!($($tail)*)
46+
tag!(<>) | tag!($($tail)*)
8247
};
8348

8449
// Any end tag
8550
(</>) => {
86-
tag!(</>)
51+
crate::tokenizer::Tag { kind: crate::tokenizer::EndTag, .. }
8752
};
8853
(</>|$($tail:tt)*) => {
89-
tag!(</>) | tags!($($tail)*)
54+
tag!(</>) | tag!($($tail)*)
9055
};
9156

9257
// Named start tag
9358
(<$tag:tt>) => {
94-
tag!(<$tag>)
59+
crate::tokenizer::Tag { kind: crate::tokenizer::StartTag, name: local_name!($tag), .. }
9560
};
9661
(<$tag:tt>|$($tail:tt)*) => {
97-
tag!(<$tag>) | tags!($($tail)*)
62+
tag!(<$tag>) | tag!($($tail)*)
9863
};
9964

10065
// Named end tag
10166
(</$tag:tt>) => {
102-
tag!(</$tag>)
67+
crate::tokenizer::Tag { kind: crate::tokenizer::EndTag, name: local_name!($tag), .. }
10368
};
10469
(</$tag:tt>|$($tail:tt)*) => {
105-
tag!(</$tag>) | tags!($($tail)*)
70+
tag!(</$tag>) | tag!($($tail)*)
10671
};
10772
}
10873

10974
macro_rules! is_not_tag {
11075
($input:ident, $($tail:tt)*) => {
111-
!matches!($input, tags!($($tail)*))
76+
!matches!($input, tag!($($tail)*))
11277
};
11378
}
11479

80+
#[rustfmt::skip]
11581
macro_rules! tag_token {
11682
($id:ident @ $($tail:tt)*) => {
117-
crate::tree_builder::types::Token::Tag(
118-
$id @ ( tags!($($tail)*) )
119-
)
83+
crate::tree_builder::types::Token::Tag($id @ ( tag!($($tail)*) ) )
12084
};
12185
($($tail:tt)*) => {
122-
crate::tree_builder::types::Token::Tag(
123-
tags!($($tail)*)
124-
)
125-
};
126-
}
127-
128-
macro_rules! any_end_tag {
129-
() => {
130-
crate::tokenizer::Tag {
131-
kind: crate::tokenizer::EndTag,
132-
..
133-
}
134-
};
135-
}
136-
137-
macro_rules! any_end_tag_token {
138-
() => {
139-
any_end_tag_token!(_)
140-
};
141-
($tag:ident) => {
142-
crate::tree_builder::types::Token::Tag(
143-
$tag @ any_end_tag!()
144-
)
86+
crate::tree_builder::types::Token::Tag( tag!($($tail)*) )
14587
};
14688
}
14789

@@ -155,43 +97,28 @@ where
15597
self.debug_step(mode, &token);
15698

15799
match mode {
158-
//§ the-initial-insertion-mode
159-
InsertionMode::Initial => match token {
160-
Token::Characters(SplitStatus::NotSplit, text) => {
161-
ProcessResult::SplitWhitespace(text)
162-
},
100+
//§ the-initial-insertion-mod
101+
//§ the-before-html-insertion-mode
102+
InsertionMode::Initial => match_token!(token {
103+
Token::Characters(SplitStatus::NotSplit, text) => ProcessResult::SplitWhitespace(text),
163104
Token::Characters(SplitStatus::Whitespace, _) => ProcessResult::Done,
164105
Token::Comment(text) => self.append_comment_to_doc(text),
165-
token => {
166-
if !self.opts.iframe_srcdoc {
167-
self.unexpected(&token);
168-
self.set_quirks_mode(Quirks);
169-
}
170-
ProcessResult::Reprocess(InsertionMode::BeforeHtml, token)
171-
},
172-
},
173106

174-
//§ the-before-html-insertion-mode
175-
// InsertionMode::BeforeHtml => match_token!(token {
176-
// Token::Characters(SplitStatus::NotSplit, text) => ProcessResult::SplitWhitespace(text),
177-
// Token::Characters(SplitStatus::Whitespace, _) => ProcessResult::Done,
178-
// Token::Comment(text) => self.append_comment_to_doc(text),
179-
180-
// tag @ <html> => {
181-
// self.create_root(tag.attrs);
182-
// self.mode.set(InsertionMode::BeforeHead);
183-
// ProcessResult::Done
184-
// }
107+
tag @ <html> => {
108+
self.create_root(tag.attrs);
109+
self.mode.set(InsertionMode::BeforeHead);
110+
ProcessResult::Done
111+
}
185112

186-
// </head> </body> </html> </br> => else,
113+
</head> </body> </html> </br> => else,
187114

188-
// tag @ </_> => self.unexpected(&tag),
115+
tag @ </_> => self.unexpected(&tag),
189116

190-
// token => {
191-
// self.create_root(vec!());
192-
// ProcessResult::Reprocess(InsertionMode::BeforeHead, token)
193-
// }
194-
// }),
117+
token => {
118+
self.create_root(vec!());
119+
ProcessResult::Reprocess(InsertionMode::BeforeHead, token)
120+
}
121+
}),
195122

196123
//§ the-before-html-insertion-mode
197124
InsertionMode::BeforeHtml => match token {
@@ -201,14 +128,13 @@ where
201128
Token::Characters(SplitStatus::Whitespace, _) => ProcessResult::Done,
202129
Token::Comment(text) => self.append_comment_to_doc(text),
203130

204-
// tag_token!(tag @ <"html"> | </"body">) => {
205-
Token::Tag(tag @ tags!(<html> | </body>)) => {
131+
Token::Tag(tag @ tag!(<html> | </body>)) => {
206132
self.create_root(tag.attrs);
207133
self.mode.set(InsertionMode::BeforeHead);
208134
ProcessResult::Done
209135
},
210136

211-
// any_end_tag_token!(tag) if !matches(tag, </"head"> | </"body"> | </"html"> | </"br">) => {
137+
// tag_token!(</>) if !matches(tag, </"head"> | </"body"> | </"html"> | </"br">) => {
212138
Token::Tag(tag @ tag!(</>)) if is_not_tag!(tag, </head> | </body> | </html> | </br>) => {
213139
self.unexpected(&tag)
214140
},

0 commit comments

Comments
 (0)