@@ -34,6 +34,59 @@ fn current_node<Handle>(open_elems: &[Handle]) -> &Handle {
34
34
open_elems. last ( ) . expect ( "no current element" )
35
35
}
36
36
37
+ macro_rules! tag {
38
+ ( $( $tag: tt ) |+) => {
39
+ $( tag!( __inner: $tag) ) |+
40
+ } ;
41
+ // Named end tag
42
+ ( __inner: [ /$tag: tt] ) => {
43
+ crate :: tokenizer:: Tag { kind: crate :: tokenizer:: EndTag , name: local_name!( $tag) , .. }
44
+ } ;
45
+ // Named start tag
46
+ ( __inner: [ $tag: tt] ) => {
47
+ crate :: tokenizer:: Tag { kind: crate :: tokenizer:: StartTag , name: local_name!( $tag) , .. }
48
+ } ;
49
+ }
50
+
51
+ macro_rules! is_not_tag {
52
+ ( $input: ident, $( $tag: tt ) |+) => {
53
+ !matches!( $input, $( tag!( __inner: $tag) ) |+)
54
+ } ;
55
+ }
56
+
57
+ macro_rules! tag_token {
58
+ ( $id: ident @ $( $tag: tt ) |+) => {
59
+ crate :: tree_builder:: types:: Token :: Tag (
60
+ $id @ ( tag!( $( $tag) |+) )
61
+ )
62
+ } ;
63
+ ( $( $tag: tt) |+) => {
64
+ crate :: tree_builder:: types:: Token :: Tag (
65
+ tag!( $( $tag) |+)
66
+ )
67
+ } ;
68
+ }
69
+
70
+ macro_rules! any_end_tag {
71
+ ( ) => {
72
+ crate :: tokenizer:: Tag {
73
+ kind: crate :: tokenizer:: EndTag ,
74
+ ..
75
+ }
76
+ } ;
77
+ }
78
+
79
+ macro_rules! any_end_tag_token {
80
+ ( ) => {
81
+ any_end_tag_token!( _)
82
+ } ;
83
+ ( $tag: ident) => {
84
+ crate :: tree_builder:: types:: Token :: Tag (
85
+ $tag @ any_end_tag!( )
86
+ )
87
+ } ;
88
+ }
89
+
37
90
#[ doc( hidden) ]
38
91
impl < Handle , Sink > TreeBuilder < Handle , Sink >
39
92
where
45
98
46
99
match mode {
47
100
//§ the-initial-insertion-mode
48
- InsertionMode :: Initial => match_token ! ( token {
49
- Token :: Characters ( SplitStatus :: NotSplit , text) => ProcessResult :: SplitWhitespace ( text) ,
101
+ InsertionMode :: Initial => match token {
102
+ Token :: Characters ( SplitStatus :: NotSplit , text) => {
103
+ ProcessResult :: SplitWhitespace ( text)
104
+ } ,
50
105
Token :: Characters ( SplitStatus :: Whitespace , _) => ProcessResult :: Done ,
51
106
Token :: Comment ( text) => self . append_comment_to_doc ( text) ,
52
107
token => {
@@ -55,30 +110,53 @@ where
55
110
self . set_quirks_mode ( Quirks ) ;
56
111
}
57
112
ProcessResult :: Reprocess ( InsertionMode :: BeforeHtml , token)
58
- }
59
- } ) ,
113
+ } ,
114
+ } ,
60
115
61
116
//§ the-before-html-insertion-mode
62
- InsertionMode :: BeforeHtml => match_token ! ( token {
63
- Token :: Characters ( SplitStatus :: NotSplit , text) => ProcessResult :: SplitWhitespace ( text) ,
117
+ // InsertionMode::BeforeHtml => match_token!(token {
118
+ // Token::Characters(SplitStatus::NotSplit, text) => ProcessResult::SplitWhitespace(text),
119
+ // Token::Characters(SplitStatus::Whitespace, _) => ProcessResult::Done,
120
+ // Token::Comment(text) => self.append_comment_to_doc(text),
121
+
122
+ // tag @ <html> => {
123
+ // self.create_root(tag.attrs);
124
+ // self.mode.set(InsertionMode::BeforeHead);
125
+ // ProcessResult::Done
126
+ // }
127
+
128
+ // </head> </body> </html> </br> => else,
129
+
130
+ // tag @ </_> => self.unexpected(&tag),
131
+
132
+ // token => {
133
+ // self.create_root(vec!());
134
+ // ProcessResult::Reprocess(InsertionMode::BeforeHead, token)
135
+ // }
136
+ // }),
137
+
138
+ //§ the-before-html-insertion-mode
139
+ InsertionMode :: BeforeHtml => match token {
140
+ Token :: Characters ( SplitStatus :: NotSplit , text) => {
141
+ ProcessResult :: SplitWhitespace ( text)
142
+ } ,
64
143
Token :: Characters ( SplitStatus :: Whitespace , _) => ProcessResult :: Done ,
65
144
Token :: Comment ( text) => self . append_comment_to_doc ( text) ,
66
-
67
- tag @ < html> => {
145
+ // Token::Tag(tag @ tag!(["html"] | [/"body"])) => {
146
+ tag_token ! ( tag @ [ " html" ] | [ / "body" ] ) => {
68
147
self . create_root ( tag. attrs ) ;
69
148
self . mode . set ( InsertionMode :: BeforeHead ) ;
70
149
ProcessResult :: Done
71
- }
72
-
73
- </head> </body> </html> </br> => else,
74
-
75
- tag @ </_> => self . unexpected( & tag) ,
76
-
150
+ } ,
151
+ // Token::Tag(tag @ any_end_tag!()) if !matches!(tag, tag!([/"head"] | [/"body"] | [/"html"] | [/"br"])) =>
152
+ any_end_tag_token ! ( tag) if is_not_tag ! ( tag, [ /"head" ] | [ /"body" ] | [ /"html" ] | [ /"br" ] ) => {
153
+ self . unexpected ( & tag)
154
+ } ,
77
155
token => {
78
- self . create_root( vec!( ) ) ;
156
+ self . create_root ( vec ! [ ] ) ;
79
157
ProcessResult :: Reprocess ( InsertionMode :: BeforeHead , token)
80
- }
81
- } ) ,
158
+ } ,
159
+ } ,
82
160
83
161
//§ the-before-head-insertion-mode
84
162
InsertionMode :: BeforeHead => match_token ! ( token {
@@ -949,43 +1027,72 @@ where
949
1027
} ) ,
950
1028
951
1029
//§ parsing-main-incolgroup
952
- InsertionMode :: InColumnGroup => match_token ! ( token {
953
- Token :: Characters ( SplitStatus :: NotSplit , text) => ProcessResult :: SplitWhitespace ( text) ,
1030
+ InsertionMode :: InColumnGroup => match token {
1031
+ Token :: Characters ( SplitStatus :: NotSplit , text) => {
1032
+ ProcessResult :: SplitWhitespace ( text)
1033
+ } ,
954
1034
Token :: Characters ( SplitStatus :: Whitespace , text) => self . append_text ( text) ,
955
1035
Token :: Comment ( text) => self . append_comment ( text) ,
956
-
957
- <html> => self . step( InsertionMode :: InBody , token) ,
958
-
959
- tag @ <col> => {
1036
+ crate :: tree_builder:: types:: Token :: Tag ( crate :: tokenizer:: Tag {
1037
+ kind : crate :: tokenizer:: StartTag ,
1038
+ name : local_name ! ( "html" ) ,
1039
+ ..
1040
+ } ) => self . step ( InsertionMode :: InBody , token) ,
1041
+ crate :: tree_builder:: types:: Token :: Tag (
1042
+ tag @ crate :: tokenizer:: Tag {
1043
+ kind : crate :: tokenizer:: StartTag ,
1044
+ name : local_name ! ( "col" ) ,
1045
+ ..
1046
+ } ,
1047
+ ) => {
960
1048
self . insert_and_pop_element_for ( tag) ;
961
1049
ProcessResult :: DoneAckSelfClosing
962
- }
963
-
964
- </colgroup> => {
1050
+ } ,
1051
+ crate :: tree_builder:: types:: Token :: Tag ( crate :: tokenizer:: Tag {
1052
+ kind : crate :: tokenizer:: EndTag ,
1053
+ name : local_name ! ( "colgroup" ) ,
1054
+ ..
1055
+ } ) => {
965
1056
if self . current_node_named ( local_name ! ( "colgroup" ) ) {
966
1057
self . pop ( ) ;
967
1058
self . mode . set ( InsertionMode :: InTable ) ;
968
1059
} else {
969
1060
self . unexpected ( & token) ;
970
1061
}
971
1062
ProcessResult :: Done
972
- }
973
-
974
- </col> => self . unexpected( & token) ,
975
-
976
- <template> </template> => self . step( InsertionMode :: InHead , token) ,
977
-
1063
+ } ,
1064
+ crate :: tree_builder:: types:: Token :: Tag ( crate :: tokenizer:: Tag {
1065
+ kind : crate :: tokenizer:: EndTag ,
1066
+ name : local_name ! ( "col" ) ,
1067
+ ..
1068
+ } ) => self . unexpected ( & token) ,
1069
+ crate :: tree_builder:: types:: Token :: Tag ( crate :: tokenizer:: Tag {
1070
+ kind : crate :: tokenizer:: StartTag ,
1071
+ name : local_name ! ( "template" ) ,
1072
+ ..
1073
+ } )
1074
+ | crate :: tree_builder:: types:: Token :: Tag ( crate :: tokenizer:: Tag {
1075
+ kind : crate :: tokenizer:: EndTag ,
1076
+ name : local_name ! ( "template" ) ,
1077
+ ..
1078
+ } ) => self . step ( InsertionMode :: InHead , token) ,
978
1079
Token :: Eof => self . step ( InsertionMode :: InBody , token) ,
979
-
980
- token => {
981
- if self . current_node_named( local_name!( "colgroup" ) ) {
982
- self . pop( ) ;
983
- ProcessResult :: Reprocess ( InsertionMode :: InTable , token)
984
- } else {
985
- self . unexpected( & token)
1080
+ last_arm_token => {
1081
+ let enable_wildcards = match last_arm_token {
1082
+ _ => true ,
1083
+ } ;
1084
+ match ( enable_wildcards, last_arm_token) {
1085
+ ( _, token) => {
1086
+ if self . current_node_named ( local_name ! ( "colgroup" ) ) {
1087
+ self . pop ( ) ;
1088
+ ProcessResult :: Reprocess ( InsertionMode :: InTable , token)
1089
+ } else {
1090
+ self . unexpected ( & token)
1091
+ }
1092
+ } ,
986
1093
}
987
- }
988
- } ) ,
1094
+ } ,
1095
+ } ,
989
1096
990
1097
//§ parsing-main-intbody
991
1098
InsertionMode :: InTableBody => match_token ! ( token {
0 commit comments