Fix case where indentation was causing the plain list item matcher to match items it wouldn't use in other parts.
This commit is contained in:
parent
143ac49777
commit
8549a6b0db
@ -9,7 +9,7 @@ cd "$DIR"
|
||||
: ${org_dir:="$DIR/../org_mode_samples"}
|
||||
: ${compare_bin:="$DIR/../target/debug/org_compare"}
|
||||
|
||||
test_files=$(find $org_dir -type f -name '*.org')
|
||||
test_files=$(find $org_dir -type f -name '*.org' | sort)
|
||||
|
||||
cargo build --bin org_compare
|
||||
|
||||
|
@ -29,6 +29,7 @@ use nom::combinator::verify;
|
||||
use nom::multi::many1;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::tuple;
|
||||
use tracing::span;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, PlainList<'s>> {
|
||||
@ -56,10 +57,15 @@ pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
|
||||
Don't consume, no additional item
|
||||
Consume, additional item
|
||||
*/
|
||||
{
|
||||
let span = span!(tracing::Level::DEBUG, "first");
|
||||
let _enter = span.enter();
|
||||
|
||||
let last_item_then_exit = tuple((without_consume_matcher, exit_matcher))(remaining);
|
||||
match last_item_then_exit {
|
||||
Ok((remain, (item, _exit)))
|
||||
if item.indentation == *first_item_indentation.get_or_insert(item.indentation) =>
|
||||
if item.indentation
|
||||
== *first_item_indentation.get_or_insert(item.indentation) =>
|
||||
{
|
||||
remaining = remain;
|
||||
children.push(item);
|
||||
@ -67,11 +73,20 @@ pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
|
||||
}
|
||||
Ok(_) | Err(_) => {}
|
||||
};
|
||||
}
|
||||
|
||||
let not_last_item = tuple((with_consume_matcher, peek(without_consume_matcher)))(remaining);
|
||||
{
|
||||
let span = span!(tracing::Level::DEBUG, "second");
|
||||
let _enter = span.enter();
|
||||
|
||||
let not_last_item =
|
||||
tuple((with_consume_matcher, peek(without_consume_matcher)))(remaining);
|
||||
match not_last_item {
|
||||
Ok((remain, (item, _future_item)))
|
||||
if item.indentation == *first_item_indentation.get_or_insert(item.indentation) =>
|
||||
Ok((remain, (item, future_item)))
|
||||
if item.indentation
|
||||
== *first_item_indentation.get_or_insert(item.indentation)
|
||||
&& future_item.indentation
|
||||
== *first_item_indentation.get_or_insert(item.indentation) =>
|
||||
{
|
||||
remaining = remain;
|
||||
children.push(item);
|
||||
@ -79,18 +94,25 @@ pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
|
||||
}
|
||||
Ok(_) | Err(_) => {}
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
let span = span!(tracing::Level::DEBUG, "third");
|
||||
let _enter = span.enter();
|
||||
|
||||
// If its not (don't consume, exit) and its not (consume, see another item) then it must be (don't consume, no additional item)
|
||||
let last_item_then_exit = without_consume_matcher(remaining);
|
||||
match last_item_then_exit {
|
||||
Ok((remain, item))
|
||||
if item.indentation == *first_item_indentation.get_or_insert(item.indentation) =>
|
||||
if item.indentation
|
||||
== *first_item_indentation.get_or_insert(item.indentation) =>
|
||||
{
|
||||
remaining = remain;
|
||||
children.push(item);
|
||||
break;
|
||||
}
|
||||
Ok(_) | Err(_) => {
|
||||
// TODO: Maybe this is reachable when there are no items at all.
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Should be unreachable.",
|
||||
))));
|
||||
@ -98,6 +120,7 @@ pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if children.is_empty() {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
|
Loading…
x
Reference in New Issue
Block a user