Identified the problem.
The issue is plain text is eating the line break so paragraph is failing since it expects a line break at the end.
This commit is contained in:
parent
e1fbe36297
commit
028946ec90
@ -83,8 +83,7 @@ pub fn document(input: &str) -> Res<&str, Document> {
|
||||
let section_matcher = parser_with_context!(section)(&document_context);
|
||||
let heading_matcher = parser_with_context!(heading)(&document_context);
|
||||
let (remaining, zeroth_section) = opt(section_matcher)(input)?;
|
||||
// let (remaining, children) = many0(heading_matcher)(remaining)?;
|
||||
let children = Vec::new();
|
||||
let (remaining, children) = many0(heading_matcher)(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
remaining,
|
||||
|
@ -24,6 +24,7 @@ impl<'s> Source<'s> for Element<'s> {
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn element<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Element<'s>> {
|
||||
let non_paragraph_matcher = parser_with_context!(non_paragraph_element)(context);
|
||||
let paragraph_matcher = parser_with_context!(paragraph)(context);
|
||||
|
@ -39,6 +39,7 @@ impl<'s> Source<'s> for Object<'s> {
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn standard_set_object<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
|
@ -19,6 +19,7 @@ use super::util::get_consumed;
|
||||
use super::util::trailing_whitespace;
|
||||
use super::Context;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn paragraph<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Paragraph<'s>> {
|
||||
let parser_context =
|
||||
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
@ -35,6 +36,7 @@ pub fn paragraph<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st
|
||||
Ok((remaining, Paragraph { source, children }))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
fn paragraph_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
let non_paragraph_element_matcher = parser_with_context!(non_paragraph_element)(context);
|
||||
alt((
|
||||
|
@ -8,6 +8,7 @@ use super::error::MyError;
|
||||
use super::error::Res;
|
||||
use super::list::List;
|
||||
use super::list::Node;
|
||||
use super::util::always_fail;
|
||||
use super::Context;
|
||||
|
||||
type Matcher = dyn for<'r, 's> Fn(Context<'r, 's>, &'s str) -> Res<&'s str, &'s str>;
|
||||
@ -64,20 +65,25 @@ impl<'r, 's> ContextTree<'r, 's> {
|
||||
return at_end_of_file;
|
||||
}
|
||||
|
||||
let blocked_context =
|
||||
self.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||
exit_matcher: ChainBehavior::IgnoreParent(Some(&always_fail)),
|
||||
}));
|
||||
|
||||
for current_node in self.iter() {
|
||||
let context_element = current_node.get_data();
|
||||
match context_element {
|
||||
ContextElement::ExitMatcherNode(exit_matcher) => {
|
||||
match exit_matcher.exit_matcher {
|
||||
ChainBehavior::AndParent(Some(matcher)) => {
|
||||
let local_result = matcher(self, i);
|
||||
let local_result = matcher(&blocked_context, i);
|
||||
if local_result.is_ok() {
|
||||
return local_result;
|
||||
}
|
||||
}
|
||||
ChainBehavior::AndParent(None) => {}
|
||||
ChainBehavior::IgnoreParent(Some(matcher)) => {
|
||||
let local_result = matcher(self, i);
|
||||
let local_result = matcher(&blocked_context, i);
|
||||
if local_result.is_ok() {
|
||||
return local_result;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ use nom::multi::many0;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, PlainList<'s>> {
|
||||
let (remaining, first_item) = plain_list_item(context, input)?;
|
||||
let plain_list_item_matcher = parser_with_context!(plain_list_item)(context);
|
||||
@ -41,7 +41,7 @@ pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
|
||||
Ok((remaining, PlainList { source, children }))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn plain_list_item<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
@ -72,6 +72,7 @@ pub fn plain_list_item<'r, 's>(
|
||||
))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
fn bullet<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
||||
alt((
|
||||
tag("*"),
|
||||
@ -81,10 +82,12 @@ fn bullet<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
||||
))(i)
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
fn counter<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
||||
alt((recognize(one_of("abcdefghijklmnopqrstuvwxyz")), digit1))(i)
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
fn plain_list_item_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
let plain_list_item_matcher = parser_with_context!(plain_list_item)(context);
|
||||
let line_indented_lte_matcher = parser_with_context!(line_indented_lte)(context);
|
||||
@ -95,6 +98,7 @@ fn plain_list_item_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<
|
||||
))(input)
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
fn line_indented_lte<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
let current_item_indent_level: &usize =
|
||||
get_context_item_indent(context).ok_or(nom::Err::Error(CustomError::MyError(MyError(
|
||||
|
@ -7,6 +7,7 @@ use super::error::Res;
|
||||
use super::object::PlainText;
|
||||
use super::Context;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn plain_text<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, PlainText<'s>> {
|
||||
if input.len() == 0 {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
|
@ -71,16 +71,19 @@ pub fn get_consumed<'s>(input: &'s str, remaining: &'s str) -> &'s str {
|
||||
/// A line containing only whitespace and then a line break
|
||||
///
|
||||
/// It is up to the caller to ensure this is called at the start of a line.
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn blank_line(input: &str) -> Res<&str, &str> {
|
||||
not(eof)(input)?;
|
||||
recognize(tuple((space0, alt((line_ending, eof)))))(input)
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn trailing_whitespace(input: &str) -> Res<&str, &str> {
|
||||
alt((eof, recognize(tuple((line_ending, many0(blank_line))))))(input)
|
||||
}
|
||||
|
||||
/// Check that we are at the start of a line
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn start_of_line<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
|
||||
let document_root = context.get_document_root().unwrap();
|
||||
let preceding_character = get_one_before(document_root, input)
|
||||
@ -103,6 +106,7 @@ pub fn start_of_line<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'
|
||||
/// Pull one non-whitespace character.
|
||||
///
|
||||
/// This function only operates on spaces, tabs, carriage returns, and line feeds. It does not handle fancy unicode whitespace.
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn non_whitespace_character(input: &str) -> Res<&str, char> {
|
||||
none_of(" \t\r\n")(input)
|
||||
}
|
||||
@ -116,6 +120,13 @@ pub fn exit_matcher_parser<'r, 's>(
|
||||
peek(|i| context.check_exit_matcher(i))(input)
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn always_fail<'r, 's>(_context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Always fail",
|
||||
))))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
Loading…
x
Reference in New Issue
Block a user