2023-03-24 21:00:27 +00:00
|
|
|
use super::error::Res;
|
2023-03-23 21:26:07 +00:00
|
|
|
use super::greater_element::PlainList;
|
|
|
|
use super::lesser_element::Paragraph;
|
2023-03-25 16:53:57 +00:00
|
|
|
use super::paragraph::paragraph;
|
2023-03-27 17:06:41 +00:00
|
|
|
use super::plain_list::plain_list;
|
2023-03-23 21:51:49 +00:00
|
|
|
use super::source::Source;
|
2023-03-24 21:00:27 +00:00
|
|
|
use super::Context;
|
2023-03-27 17:06:41 +00:00
|
|
|
use crate::parser::parser_with_context::parser_with_context;
|
|
|
|
use nom::branch::alt;
|
|
|
|
use nom::combinator::map;
|
2023-03-23 21:26:07 +00:00
|
|
|
|
2023-03-23 21:51:49 +00:00
|
|
|
#[derive(Debug)]
|
2023-03-23 21:26:07 +00:00
|
|
|
pub enum Element<'s> {
|
|
|
|
Paragraph(Paragraph<'s>),
|
|
|
|
PlainList(PlainList<'s>),
|
|
|
|
}
|
2023-03-23 21:51:49 +00:00
|
|
|
|
|
|
|
impl<'s> Source<'s> for Element<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
match self {
|
|
|
|
Element::Paragraph(obj) => obj.source,
|
|
|
|
Element::PlainList(obj) => obj.source,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-24 21:00:27 +00:00
|
|
|
|
|
|
|
pub fn element<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Element<'s>> {
|
2023-03-27 17:06:41 +00:00
|
|
|
let non_paragraph_matcher = parser_with_context!(non_paragraph_element)(context);
|
2023-03-25 15:22:59 +00:00
|
|
|
let paragraph_matcher = parser_with_context!(paragraph)(context);
|
|
|
|
|
2023-03-27 17:06:41 +00:00
|
|
|
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)
|
2023-03-25 15:22:59 +00:00
|
|
|
}
|