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

View File

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