Update the section parser to handle the new whitespace-included element parsers.
This commit is contained in:
parent
54b0ff5036
commit
cbe7ef4030
@ -107,36 +107,23 @@ fn section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Sec
|
|||||||
}));
|
}));
|
||||||
let element_matcher = parser_with_context!(element)(&parser_context);
|
let element_matcher = parser_with_context!(element)(&parser_context);
|
||||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||||
let trailing_matcher = parser_with_context!(element_trailing_whitespace)(&parser_context);
|
|
||||||
let (remaining, (children, _exit_contents)) = verify(
|
let (remaining, (children, _exit_contents)) = verify(
|
||||||
many_till(
|
many_till(element_matcher, exit_matcher),
|
||||||
tuple((
|
|
||||||
element_matcher,
|
|
||||||
opt(map(trailing_matcher, Element::TrailingWhitespace)),
|
|
||||||
)),
|
|
||||||
exit_matcher,
|
|
||||||
),
|
|
||||||
|(children, _exit_contents)| !children.is_empty(),
|
|(children, _exit_contents)| !children.is_empty(),
|
||||||
)(input)?;
|
)(input)?;
|
||||||
let flattened_children: Vec<Element> = children
|
|
||||||
.into_iter()
|
// Check if a parent exit matcher is causing the exit
|
||||||
.flat_map(|tpl| {
|
exit_matcher_parser(context, remaining)?;
|
||||||
let mut flattened_children = Vec::with_capacity(2);
|
|
||||||
flattened_children.push(tpl.0);
|
let (remaining, _trailing_ws) = if context.should_consume_trailing_whitespace() {
|
||||||
if let Some(bar) = tpl.1 {
|
opt(parser_with_context!(element_trailing_whitespace)(&parser_context))(remaining)?
|
||||||
flattened_children.push(bar);
|
|
||||||
}
|
} else {
|
||||||
flattened_children.into_iter()
|
(remaining, None)
|
||||||
})
|
};
|
||||||
.collect();
|
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((remaining, Section { source, children }))
|
||||||
remaining,
|
|
||||||
Section {
|
|
||||||
source,
|
|
||||||
children: flattened_children,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user