Fix plain list ending with another element.
This commit is contained in:
parent
9257420c83
commit
d7f0a02bb8
@ -26,20 +26,29 @@ use nom::combinator::verify;
|
|||||||
use nom::multi::many_till;
|
use nom::multi::many_till;
|
||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
|
||||||
pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, PlainList<'s>> {
|
pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, PlainList<'s>> {
|
||||||
let (remaining, first_item) = plain_list_item(context, input)?;
|
let (mut remaining, first_item) = plain_list_item(context, input)?;
|
||||||
|
let first_item_indentation = first_item.indentation;
|
||||||
let plain_list_item_matcher = parser_with_context!(plain_list_item)(context);
|
let plain_list_item_matcher = parser_with_context!(plain_list_item)(context);
|
||||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
|
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
|
||||||
// TODO: The problem is this expects the list to be followed by something that matches the exit matcher, but after we have the first plain list item, really anything that is not a plain list item is a good exit condition.
|
let mut children = Vec::new();
|
||||||
let (remaining, (mut children, _exit_contents)) = many_till(
|
children.push(first_item);
|
||||||
verify(plain_list_item_matcher, |pli| {
|
loop {
|
||||||
pli.indentation == first_item.indentation
|
let exit_contents = exit_matcher(remaining);
|
||||||
}),
|
if exit_contents.is_ok() {
|
||||||
exit_matcher,
|
break;
|
||||||
)(remaining)?;
|
}
|
||||||
|
|
||||||
|
let next_list_item = plain_list_item_matcher(remaining);
|
||||||
|
match next_list_item {
|
||||||
|
Ok((remain, next_child)) if next_child.indentation == first_item_indentation => {
|
||||||
|
children.push(next_child);
|
||||||
|
remaining = remain;
|
||||||
|
}
|
||||||
|
Ok(_) | Err(_) => break,
|
||||||
|
};
|
||||||
|
}
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
children.insert(0, first_item);
|
|
||||||
Ok((remaining, PlainList { source, children }))
|
Ok((remaining, PlainList { source, children }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user