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"}
|
: ${org_dir:="$DIR/../org_mode_samples"}
|
||||||
: ${compare_bin:="$DIR/../target/debug/org_compare"}
|
: ${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
|
cargo build --bin org_compare
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ use nom::combinator::verify;
|
|||||||
use nom::multi::many1;
|
use nom::multi::many1;
|
||||||
use nom::multi::many_till;
|
use nom::multi::many_till;
|
||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
|
use tracing::span;
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[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>> {
|
||||||
@ -55,48 +56,70 @@ pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
|
|||||||
Don't consume, yes exit matcher
|
Don't consume, yes exit matcher
|
||||||
Don't consume, no additional item
|
Don't consume, no additional item
|
||||||
Consume, additional item
|
Consume, additional item
|
||||||
*/
|
*/
|
||||||
let last_item_then_exit = tuple((without_consume_matcher, exit_matcher))(remaining);
|
{
|
||||||
match last_item_then_exit {
|
let span = span!(tracing::Level::DEBUG, "first");
|
||||||
Ok((remain, (item, _exit)))
|
let _enter = span.enter();
|
||||||
if item.indentation == *first_item_indentation.get_or_insert(item.indentation) =>
|
|
||||||
{
|
|
||||||
remaining = remain;
|
|
||||||
children.push(item);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Ok(_) | Err(_) => {}
|
|
||||||
};
|
|
||||||
|
|
||||||
let not_last_item = tuple((with_consume_matcher, peek(without_consume_matcher)))(remaining);
|
let last_item_then_exit = tuple((without_consume_matcher, exit_matcher))(remaining);
|
||||||
match not_last_item {
|
match last_item_then_exit {
|
||||||
Ok((remain, (item, _future_item)))
|
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);
|
remaining = remain;
|
||||||
continue;
|
children.push(item);
|
||||||
}
|
break;
|
||||||
Ok(_) | Err(_) => {}
|
}
|
||||||
};
|
Ok(_) | Err(_) => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// 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);
|
let span = span!(tracing::Level::DEBUG, "second");
|
||||||
match last_item_then_exit {
|
let _enter = span.enter();
|
||||||
Ok((remain, item))
|
|
||||||
if item.indentation == *first_item_indentation.get_or_insert(item.indentation) =>
|
let not_last_item =
|
||||||
{
|
tuple((with_consume_matcher, peek(without_consume_matcher)))(remaining);
|
||||||
remaining = remain;
|
match not_last_item {
|
||||||
children.push(item);
|
Ok((remain, (item, future_item)))
|
||||||
break;
|
if item.indentation
|
||||||
}
|
== *first_item_indentation.get_or_insert(item.indentation)
|
||||||
Ok(_) | Err(_) => {
|
&& future_item.indentation
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
== *first_item_indentation.get_or_insert(item.indentation) =>
|
||||||
"Should be unreachable.",
|
{
|
||||||
))));
|
remaining = remain;
|
||||||
unreachable!();
|
children.push(item);
|
||||||
}
|
continue;
|
||||||
};
|
}
|
||||||
|
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) =>
|
||||||
|
{
|
||||||
|
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.",
|
||||||
|
))));
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if children.is_empty() {
|
if children.is_empty() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user