Integrate plain list parser into the parser tree.
This commit is contained in:
parent
81a9a754de
commit
22a2ed29f1
@ -11,6 +11,7 @@ use nom::combinator::verify;
|
||||
use nom::multi::many0;
|
||||
use nom::multi::many1;
|
||||
use nom::multi::many1_count;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use crate::parser::element::element;
|
||||
@ -25,6 +26,7 @@ use super::error::Res;
|
||||
use super::object::Object;
|
||||
use super::parser_with_context::parser_with_context;
|
||||
use super::source::Source;
|
||||
use super::util::exit_matcher_parser;
|
||||
use super::util::get_consumed;
|
||||
use super::util::start_of_line;
|
||||
use super::util::trailing_whitespace;
|
||||
@ -101,7 +103,11 @@ fn section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Sec
|
||||
.with_additional_node(ContextElement::Context("section"));
|
||||
not(|i| parser_context.check_exit_matcher(i))(input)?;
|
||||
let element_matcher = parser_with_context!(element)(&parser_context);
|
||||
let (remaining, children) = many1(element_matcher)(input)?;
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||
let (remaining, (children, _exit_contents)) = verify(
|
||||
many_till(element_matcher, exit_matcher),
|
||||
|(children, _exit_contents)| !children.is_empty(),
|
||||
)(input)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, Section { source, children }))
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
use crate::parser::parser_with_context::parser_with_context;
|
||||
use nom::combinator::map;
|
||||
use nom::combinator::not;
|
||||
|
||||
use super::error::Res;
|
||||
use super::greater_element::PlainList;
|
||||
use super::lesser_element::Paragraph;
|
||||
use super::paragraph::paragraph;
|
||||
use super::plain_list::plain_list;
|
||||
use super::source::Source;
|
||||
use super::Context;
|
||||
use crate::parser::parser_with_context::parser_with_context;
|
||||
use nom::branch::alt;
|
||||
use nom::combinator::map;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Element<'s> {
|
||||
@ -25,9 +25,19 @@ impl<'s> Source<'s> for Element<'s> {
|
||||
}
|
||||
|
||||
pub fn element<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Element<'s>> {
|
||||
not(|i| context.check_exit_matcher(i))(input)?;
|
||||
|
||||
let non_paragraph_matcher = parser_with_context!(non_paragraph_element)(context);
|
||||
let paragraph_matcher = parser_with_context!(paragraph)(context);
|
||||
|
||||
map(paragraph_matcher, Element::Paragraph)(input)
|
||||
alt((
|
||||
non_paragraph_matcher,
|
||||
map(paragraph_matcher, Element::Paragraph),
|
||||
))(input)
|
||||
}
|
||||
|
||||
pub fn non_paragraph_element<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, Element<'s>> {
|
||||
let plain_list_matcher = parser_with_context!(plain_list)(context);
|
||||
map(plain_list_matcher, Element::PlainList)(input)
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ use crate::parser::parser_context::ContextElement;
|
||||
use crate::parser::parser_context::ExitMatcherNode;
|
||||
use crate::parser::parser_with_context::parser_with_context;
|
||||
|
||||
use super::element::non_paragraph_element;
|
||||
use super::error::Res;
|
||||
use super::lesser_element::Paragraph;
|
||||
use super::util::blank_line;
|
||||
@ -35,6 +36,10 @@ pub fn paragraph<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st
|
||||
}
|
||||
|
||||
fn paragraph_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
// TODO: Other elements should also end paragraphs
|
||||
alt((recognize(tuple((line_ending, many1(blank_line)))), eof))(input)
|
||||
let non_paragraph_element_matcher = parser_with_context!(non_paragraph_element)(context);
|
||||
alt((
|
||||
recognize(tuple((line_ending, many1(blank_line)))),
|
||||
recognize(non_paragraph_element_matcher),
|
||||
eof,
|
||||
))(input)
|
||||
}
|
||||
|
@ -1,24 +1,3 @@
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::digit1;
|
||||
use nom::character::complete::one_of;
|
||||
use nom::character::complete::space0;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::not;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many0;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use crate::parser::element::element;
|
||||
use crate::parser::parser_context::ChainBehavior;
|
||||
use crate::parser::parser_context::ContextElement;
|
||||
use crate::parser::parser_context::ExitMatcherNode;
|
||||
use crate::parser::util::exit_matcher_parser;
|
||||
use crate::parser::util::get_consumed;
|
||||
use crate::parser::util::start_of_line;
|
||||
|
||||
use super::error::CustomError;
|
||||
use super::error::MyError;
|
||||
use super::error::Res;
|
||||
@ -27,6 +6,24 @@ use super::greater_element::PlainListItem;
|
||||
use super::parser_with_context::parser_with_context;
|
||||
use super::util::non_whitespace_character;
|
||||
use super::Context;
|
||||
use crate::parser::element::element;
|
||||
use crate::parser::parser_context::ChainBehavior;
|
||||
use crate::parser::parser_context::ContextElement;
|
||||
use crate::parser::parser_context::ExitMatcherNode;
|
||||
use crate::parser::util::exit_matcher_parser;
|
||||
use crate::parser::util::get_consumed;
|
||||
use crate::parser::util::start_of_line;
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::digit1;
|
||||
use nom::character::complete::one_of;
|
||||
use nom::character::complete::space0;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many0;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, PlainList<'s>> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user