2023-03-25 12:53:57 -04:00
|
|
|
use crate::parser::parser_with_context::parser_with_context;
|
2023-03-25 11:22:59 -04:00
|
|
|
use nom::combinator::map;
|
2023-03-24 17:00:27 -04:00
|
|
|
use nom::combinator::not;
|
|
|
|
|
|
|
|
use super::error::Res;
|
2023-03-23 17:26:07 -04:00
|
|
|
use super::greater_element::PlainList;
|
|
|
|
use super::lesser_element::Paragraph;
|
2023-03-25 12:53:57 -04:00
|
|
|
use super::paragraph::paragraph;
|
2023-03-23 17:51:49 -04:00
|
|
|
use super::source::Source;
|
2023-03-24 17:00:27 -04:00
|
|
|
use super::Context;
|
2023-03-23 17:26:07 -04:00
|
|
|
|
2023-03-23 17:51:49 -04:00
|
|
|
#[derive(Debug)]
|
2023-03-23 17:26:07 -04:00
|
|
|
pub enum Element<'s> {
|
|
|
|
Paragraph(Paragraph<'s>),
|
|
|
|
PlainList(PlainList<'s>),
|
|
|
|
}
|
2023-03-23 17:51:49 -04: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 17:00:27 -04:00
|
|
|
|
|
|
|
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)?;
|
2023-03-25 11:22:59 -04:00
|
|
|
|
|
|
|
let paragraph_matcher = parser_with_context!(paragraph)(context);
|
|
|
|
|
|
|
|
map(paragraph_matcher, Element::Paragraph)(input)
|
|
|
|
}
|