From b0930df7882cc559d54acb15f455dbc4d4bde049 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 7 Sep 2023 04:15:17 -0400 Subject: [PATCH] Support zero skipped text in OrgSource slicing. --- src/parser/org_source.rs | 5 ++++- src/parser/util.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/parser/org_source.rs b/src/parser/org_source.rs index 87f93da..820c01c 100644 --- a/src/parser/org_source.rs +++ b/src/parser/org_source.rs @@ -145,6 +145,9 @@ where if new_end > self.end { panic!("Attempted to extend past the end of the WrappedInput.") } + if new_start == self.start && new_end == self.end { + return self.clone(); + } let skipped_text = &self.full_source[self.start..new_start]; let mut start_of_line = self.start_of_line; @@ -183,7 +186,7 @@ where start: new_start, end: new_end, start_of_line, - preceding_character: skipped_text.chars().last(), + preceding_character: skipped_text.chars().last().or(self.preceding_character), bracket_depth, brace_depth, parenthesis_depth, diff --git a/src/parser/util.rs b/src/parser/util.rs index 6464fe8..6625b86 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -153,7 +153,7 @@ fn _preceded_by_whitespace<'s>( .unwrap_or(allow_start_of_file) { return Err(nom::Err::Error(CustomError::MyError(MyError( - "Must be preceded by a non-whitespace character.".into(), + "Must be preceded by a whitespace character.".into(), )))); } Ok((input, ()))