@@ -155,17 +155,26 @@ impl Parser {
155155
156156 let specs = TagSpec :: load_builtin_specs ( ) . unwrap_or_default ( ) ;
157157
158- // Check if this is a closing or branch tag
158+ // Check if this is a closing tag
159159 for ( _, spec) in specs. iter ( ) {
160- if Some ( & tag_name) == spec. closing . as_ref ( )
161- || spec . intermediates . as_ref ( )
162- . map ( |ints| ints . iter ( ) . any ( |i| i . name == tag_name) )
163- . unwrap_or ( false )
164- {
160+ if Some ( & tag_name) == spec. closing . as_ref ( ) {
161+ // let node = Node::Django(DjangoNode::Tag(TagNode::Closing {
162+ // name: tag_name.clone(),
163+ // bits: bits[1..].to_vec(),
164+ // }));
165165 return Err ( ParserError :: ErrorSignal ( Signal :: SpecialTag ( tag_name) ) ) ;
166166 }
167167 }
168168
169+ // Check if this is a branch tag according to any spec
170+ for ( _, spec) in specs. iter ( ) {
171+ if let Some ( branches) = & spec. branches {
172+ if branches. iter ( ) . any ( |i| i. name == tag_name) {
173+ return Err ( ParserError :: ErrorSignal ( Signal :: SpecialTag ( tag_name) ) ) ;
174+ }
175+ }
176+ }
177+
169178 let tag_spec = specs. get ( tag_name. as_str ( ) ) . cloned ( ) ;
170179 let mut children = Vec :: new ( ) ;
171180 let mut current_branch: Option < ( String , Vec < String > , Vec < Node > ) > = None ;
@@ -202,9 +211,8 @@ impl Parser {
202211 } ) ) ) ;
203212 }
204213 // Check if intermediate tag
205- if let Some ( intermediates) = & spec. intermediates {
206- if let Some ( intermediate) = intermediates. iter ( ) . find ( |i| i. name == tag)
207- {
214+ if let Some ( branches) = & spec. branches {
215+ if let Some ( branch) = branches. iter ( ) . find ( |i| i. name == tag) {
208216 // If we have a current branch, add it to children
209217 if let Some ( ( name, bits, branch_children) ) = current_branch {
210218 children. push ( Node :: Django ( DjangoNode :: Tag ( TagNode :: Branch {
@@ -214,7 +222,7 @@ impl Parser {
214222 } ) ) ) ;
215223 }
216224 // Create new branch node
217- let branch_bits = if intermediate . args {
225+ let branch_bits = if branch . args {
218226 match & self . tokens [ self . current - 1 ] . token_type ( ) {
219227 TokenType :: DjangoBlock ( content) => content
220228 . split_whitespace ( )
@@ -675,8 +683,7 @@ mod tests {
675683
676684 #[ test]
677685 fn test_parse_complex_if_elif ( ) {
678- let source =
679- "{% if x > 0 %}Positive{% elif x < 0 %}Negative{% else %}Zero{% endif %}" ;
686+ let source = "{% if x > 0 %}Positive{% elif x < 0 %}Negative{% else %}Zero{% endif %}" ;
680687 let tokens = Lexer :: new ( source) . tokenize ( ) . unwrap ( ) ;
681688 let mut parser = Parser :: new ( tokens) ;
682689 let ast = parser. parse ( ) . unwrap ( ) ;
0 commit comments