parser: understand arbitrarily mixed up end nodes

This commit is contained in:
René Kijewski 2024-08-07 20:43:18 +02:00
parent e0a7d4df55
commit 5efd31310f
4 changed files with 14 additions and 2 deletions

View File

@ -1058,7 +1058,7 @@ fn end_node<'a, 'g: 'a>(
let (i, actual) = ws(identifier)(start)?;
if actual == expected {
Ok((i, actual))
} else if actual == "end" {
} else if actual.starts_with("end") {
Err(nom::Err::Failure(ErrorContext::new(
format!("expected `{expected}` to terminate `{node}` node, found `{actual}`"),
start,

View File

@ -1,4 +1,4 @@
error: failed to parse template source
error: expected `endfor` to terminate `for` node, found `endfo`
--> <source attribute>:1:26
"endfo%}\n1234567890123456789012345678901234567890"
--> tests/ui/typo_in_keyword.rs:5:14

View File

@ -24,4 +24,8 @@ struct Block;
#[template(source = "{% if true %}{% end %}", ext = "txt")]
struct If;
#[derive(Template)]
#[template(source = "{% if true %}{% endfor %}", ext = "txt")]
struct IfFor;
fn main() {}

View File

@ -45,3 +45,11 @@ error: expected `endif` to terminate `if` node, found `end`
|
24 | #[template(source = "{% if true %}{% end %}", ext = "txt")]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: expected `endif` to terminate `if` node, found `endfor`
--> <source attribute>:1:15
" endfor %}"
--> tests/ui/wrong-end.rs:28:21
|
28 | #[template(source = "{% if true %}{% endfor %}", ext = "txt")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^