Compare commits

..

No commits in common. "e5224cda632a493d9b3c0be4d3c9684e3478dff9" and "32071ce74d0bd1480d01590e9e50b6c7f08659ce" have entirely different histories.

4 changed files with 47 additions and 8 deletions

View File

@ -20,6 +20,7 @@ use crate::parser::parser_with_context::parser_with_context;
use crate::parser::util::exit_matcher_parser;
use crate::parser::util::get_consumed;
use crate::parser::FootnoteReference;
use crate::parser::Object;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn footnote_reference<'r, 's>(
@ -133,6 +134,11 @@ fn footnote_reference_only<'r, 's>(
))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn definition<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, Vec<Object<'s>>> {
Ok((input, vec![]))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn footnote_definition_end<'r, 's>(
context: Context<'r, 's>,

View File

@ -124,7 +124,7 @@ pub fn example_block<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, ExampleBlock<'s>> {
let (remaining, _name) = lesser_block_begin("example")(context, input)?;
let (remaining, name) = lesser_block_begin("example")(context, input)?;
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
let (remaining, _nl) = line_ending(remaining)?;
let lesser_block_end_specialized = lesser_block_end("example");

View File

@ -50,12 +50,6 @@ 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> {
@ -124,6 +118,7 @@ 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,

View File

@ -1,6 +1,7 @@
use nom::branch::alt;
use nom::character::complete::anychar;
use nom::character::complete::line_ending;
use nom::character::complete::multispace0;
use nom::character::complete::none_of;
use nom::character::complete::space0;
use nom::combinator::eof;
@ -48,9 +49,26 @@ 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> {
input.get_until(remaining)
// 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()
}
/// A line containing only whitespace and then a line break
@ -100,6 +118,11 @@ pub fn maybe_consume_trailing_whitespace<'r, 's>(
}
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn trailing_whitespace(input: OrgSource<'_>) -> Res<OrgSource<'_>, OrgSource<'_>> {
alt((eof, recognize(tuple((line_ending, many0(blank_line))))))(input)
}
/// Check that we are at the start of a line
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn start_of_line<'r, 's>(
@ -151,6 +174,21 @@ pub fn exit_matcher_parser<'r, 's>(
peek(|i| context.check_exit_matcher(i))(input)
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn always_fail<'r, 's>(
_context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
Err(nom::Err::Error(CustomError::MyError(MyError(
"Always fail".into(),
))))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn whitespace_eof(input: OrgSource<'_>) -> Res<OrgSource<'_>, OrgSource<'_>> {
recognize(tuple((multispace0, eof)))(input)
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn text_until_exit<'r, 's>(
context: Context<'r, 's>,