Change section parser to wrap entire function in verify() for better error messages.

This commit is contained in:
Tom Alexander 2020-04-05 16:22:48 -04:00
parent adf2f1f2b5
commit 7d51e500d8
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -144,11 +144,14 @@ fn reference(i: &str) -> IResult<&str, Reference> {
}
fn section(i: &str) -> IResult<&str, Section> {
let (i, opening_name) = delimited(tag("{#"), path, tag("}"))(i)?;
let (i, inner) = opt(block)(i)?;
let (i, _closing_name) = verify(delimited(tag("{/"), path, tag("}")), |name: &Path| {
name == &opening_name
})(i)?;
let (i, (opening_name, inner, _closing_name)) = verify(
tuple((
delimited(tag("{#"), path, tag("}")),
opt(block),
delimited(tag("{/"), path, tag("}")),
)),
|(open, inn, close)| open == close,
)(i)?;
Ok((
i,
@ -304,7 +307,7 @@ mod tests {
fn test_section_mismatched_paths() {
assert_eq!(
super::section("{#foo.bar}{/baz}"),
Err(Error(("{/baz}", ErrorKind::Verify)))
Err(Error(("{#foo.bar}{/baz}", ErrorKind::Verify)))
);
}
@ -322,11 +325,6 @@ mod tests {
}
))
);
assert_eq!(
super::section("{#foo.bar}{/baz}"),
Err(Error(("{/baz}", ErrorKind::Verify)))
);
}
#[test]