Compare commits
2 Commits
32071ce74d
...
e5224cda63
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e5224cda63 | ||
![]() |
64e3481660 |
@ -20,7 +20,6 @@ use crate::parser::parser_with_context::parser_with_context;
|
|||||||
use crate::parser::util::exit_matcher_parser;
|
use crate::parser::util::exit_matcher_parser;
|
||||||
use crate::parser::util::get_consumed;
|
use crate::parser::util::get_consumed;
|
||||||
use crate::parser::FootnoteReference;
|
use crate::parser::FootnoteReference;
|
||||||
use crate::parser::Object;
|
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
pub fn footnote_reference<'r, 's>(
|
pub fn footnote_reference<'r, 's>(
|
||||||
@ -134,11 +133,6 @@ 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"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
fn footnote_definition_end<'r, 's>(
|
fn footnote_definition_end<'r, 's>(
|
||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
|
@ -124,7 +124,7 @@ pub fn example_block<'r, 's>(
|
|||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
input: OrgSource<'s>,
|
input: OrgSource<'s>,
|
||||||
) -> Res<OrgSource<'s>, ExampleBlock<'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, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||||
let (remaining, _nl) = line_ending(remaining)?;
|
let (remaining, _nl) = line_ending(remaining)?;
|
||||||
let lesser_block_end_specialized = lesser_block_end("example");
|
let lesser_block_end_specialized = lesser_block_end("example");
|
||||||
|
@ -50,6 +50,12 @@ impl<'s> OrgSource<'s> {
|
|||||||
pub fn is_at_start_of_line(&self) -> bool {
|
pub fn is_at_start_of_line(&self) -> bool {
|
||||||
self.start == self.start_of_line
|
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> {
|
impl<'s> InputTake for OrgSource<'s> {
|
||||||
@ -118,7 +124,6 @@ where
|
|||||||
.map(|idx| self.start + idx + 1)
|
.map(|idx| self.start + idx + 1)
|
||||||
.unwrap_or(self.start_of_line);
|
.unwrap_or(self.start_of_line);
|
||||||
|
|
||||||
// TODO: calculate updated values for WrappedInput
|
|
||||||
OrgSource {
|
OrgSource {
|
||||||
full_source: self.full_source,
|
full_source: self.full_source,
|
||||||
start: new_start,
|
start: new_start,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
use nom::character::complete::anychar;
|
use nom::character::complete::anychar;
|
||||||
use nom::character::complete::line_ending;
|
use nom::character::complete::line_ending;
|
||||||
use nom::character::complete::multispace0;
|
|
||||||
use nom::character::complete::none_of;
|
use nom::character::complete::none_of;
|
||||||
use nom::character::complete::space0;
|
use nom::character::complete::space0;
|
||||||
use nom::combinator::eof;
|
use nom::combinator::eof;
|
||||||
@ -49,26 +48,9 @@ pub fn immediate_in_section<'r, 's, 'x>(context: Context<'r, 's>, section_name:
|
|||||||
false
|
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.
|
/// 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> {
|
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.
|
input.get_until(remaining)
|
||||||
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
|
/// A line containing only whitespace and then a line break
|
||||||
@ -118,11 +100,6 @@ 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
|
/// Check that we are at the start of a line
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
pub fn start_of_line<'r, 's>(
|
pub fn start_of_line<'r, 's>(
|
||||||
@ -174,21 +151,6 @@ pub fn exit_matcher_parser<'r, 's>(
|
|||||||
peek(|i| context.check_exit_matcher(i))(input)
|
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"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
pub fn text_until_exit<'r, 's>(
|
pub fn text_until_exit<'r, 's>(
|
||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user