This commit is contained in:
Josh Thomas 2025-01-04 22:58:42 -06:00
parent ca4877d06c
commit ee7c59ecd1

View file

@ -330,35 +330,22 @@ impl Parser {
} }
fn synchronize(&mut self) -> Result<(), ParserError> { fn synchronize(&mut self) -> Result<(), ParserError> {
let mut depth = 0; let sync_types = [
let mut found_django_token = false; TokenType::DjangoBlock(String::new()),
TokenType::DjangoVariable(String::new()),
TokenType::Comment(String::new(), String::from("{#"), Some(String::from("#}"))),
TokenType::Eof,
];
while !self.is_at_end() { while !self.is_at_end() {
if let TokenType::DjangoBlock(content) = &self.tokens[self.current].token_type() { let current = self.peek()?;
let tag = content.split_whitespace().next().unwrap_or(""); for sync_type in &sync_types {
if let Some(spec) = TagSpec::load_builtin_specs().unwrap_or_default().get(tag) { if current.token_type() == sync_type {
if spec.closing.as_deref() == Some(tag) { return Ok(());
depth -= 1;
if depth <= 0 {
found_django_token = true;
break;
}
} else {
depth += 1;
}
} }
} }
self.current += 1; self.consume()?;
} }
Err(ParserError::Ast(AstError::StreamError("AtEnd".into()), None))
if !found_django_token {
return Err(ParserError::Ast(
AstError::StreamError("AtEnd".into()),
None,
));
}
Ok(())
} }
} }