Update get_consumed to use the new wrapped input type.
This commit is contained in:
parent
32071ce74d
commit
64e3481660
@ -50,6 +50,12 @@ impl<'s> OrgSource<'s> {
|
||||
pub fn is_at_start_of_line(&self) -> bool {
|
||||
self.start == self.start_of_line
|
||||
}
|
||||
|
||||
pub fn get_until(&self, other: OrgSource<'s>) -> OrgSource<'s> {
|
||||
assert!(other.start >= self.start);
|
||||
assert!(other.end <= self.end);
|
||||
self.slice(..(other.start - self.start))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> InputTake for OrgSource<'s> {
|
||||
@ -118,7 +124,6 @@ where
|
||||
.map(|idx| self.start + idx + 1)
|
||||
.unwrap_or(self.start_of_line);
|
||||
|
||||
// TODO: calculate updated values for WrappedInput
|
||||
OrgSource {
|
||||
full_source: self.full_source,
|
||||
start: new_start,
|
||||
|
@ -49,26 +49,9 @@ pub fn immediate_in_section<'r, 's, 'x>(context: Context<'r, 's>, section_name:
|
||||
false
|
||||
}
|
||||
|
||||
/// Check if the child string slice is a slice of the parent string slice.
|
||||
fn is_slice_of(parent: &str, child: &str) -> bool {
|
||||
let parent_start = parent.as_ptr() as usize;
|
||||
let parent_end = parent_start + parent.len();
|
||||
let child_start = child.as_ptr() as usize;
|
||||
let child_end = child_start + child.len();
|
||||
child_start >= parent_start && child_end <= parent_end
|
||||
}
|
||||
|
||||
/// Get a slice of the string that was consumed in a parser using the original input to the parser and the remaining input after the parser.
|
||||
pub fn get_consumed<'s>(input: OrgSource<'s>, remaining: OrgSource<'s>) -> OrgSource<'s> {
|
||||
// TODO: This should be replaced with new logic now that we are wrapping the input type.
|
||||
let input = Into::<&str>::into(&input);
|
||||
let remaining = Into::<&str>::into(&remaining);
|
||||
assert!(is_slice_of(input, remaining));
|
||||
let source = {
|
||||
let offset = remaining.as_ptr() as usize - input.as_ptr() as usize;
|
||||
&input[..offset]
|
||||
};
|
||||
source.into()
|
||||
input.get_until(remaining)
|
||||
}
|
||||
|
||||
/// A line containing only whitespace and then a line break
|
||||
|
Loading…
x
Reference in New Issue
Block a user