diff --git a/scripts/compare_parse_all.bash b/scripts/compare_parse_all.bash index 8430d232..2970b3e7 100755 --- a/scripts/compare_parse_all.bash +++ b/scripts/compare_parse_all.bash @@ -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 diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 7259fcd2..367098e8 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -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>> { @@ -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, no additional item Consume, additional item - */ - 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) => - { - remaining = remain; - children.push(item); - break; - } - Ok(_) | Err(_) => {} - }; + */ + { + let span = span!(tracing::Level::DEBUG, "first"); + 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) => - { - remaining = remain; - children.push(item); - continue; - } - Ok(_) | Err(_) => {} - }; + 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) => + { + remaining = remain; + children.push(item); + break; + } + 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); - 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(_) => { - return Err(nom::Err::Error(CustomError::MyError(MyError( - "Should be unreachable.", - )))); - unreachable!(); - } - }; + { + 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) + && future_item.indentation + == *first_item_indentation.get_or_insert(item.indentation) => + { + remaining = remain; + 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() {