2023-03-25 14:45:43 +00:00
|
|
|
use nom::combinator::map;
|
2023-03-24 00:12:42 +00:00
|
|
|
use nom::combinator::not;
|
|
|
|
|
2023-03-23 23:53:20 +00:00
|
|
|
use super::error::Res;
|
2023-03-25 14:45:43 +00:00
|
|
|
use super::parser_with_context::parser_with_context;
|
2023-03-25 16:53:57 +00:00
|
|
|
use super::plain_text::plain_text;
|
2023-03-23 21:51:49 +00:00
|
|
|
use super::source::Source;
|
2023-03-23 23:53:20 +00:00
|
|
|
use super::Context;
|
2023-03-23 21:02:08 +00:00
|
|
|
|
2023-03-23 21:26:07 +00:00
|
|
|
#[derive(Debug)]
|
2023-03-23 20:49:52 +00:00
|
|
|
pub enum Object<'s> {
|
|
|
|
TextMarkup(TextMarkup<'s>),
|
|
|
|
PlainText(PlainText<'s>),
|
2023-03-23 21:02:08 +00:00
|
|
|
RegularLink(RegularLink<'s>),
|
2023-03-23 20:49:52 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 21:26:07 +00:00
|
|
|
#[derive(Debug)]
|
2023-03-23 20:49:52 +00:00
|
|
|
pub struct TextMarkup<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
}
|
|
|
|
|
2023-03-23 21:26:07 +00:00
|
|
|
#[derive(Debug)]
|
2023-03-23 20:49:52 +00:00
|
|
|
pub struct PlainText<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
}
|
|
|
|
|
2023-03-23 21:26:07 +00:00
|
|
|
#[derive(Debug)]
|
2023-03-23 21:02:08 +00:00
|
|
|
pub struct RegularLink<'s> {
|
|
|
|
pub source: &'s str,
|
2023-03-23 20:49:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'s> Source<'s> for Object<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
match self {
|
|
|
|
Object::TextMarkup(obj) => obj.source,
|
|
|
|
Object::PlainText(obj) => obj.source,
|
2023-03-23 21:02:08 +00:00
|
|
|
Object::RegularLink(obj) => obj.source,
|
2023-03-23 20:49:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-23 23:53:20 +00:00
|
|
|
|
|
|
|
pub fn standard_set_object<'r, 's>(
|
|
|
|
context: Context<'r, 's>,
|
|
|
|
input: &'s str,
|
|
|
|
) -> Res<&'s str, Object<'s>> {
|
2023-03-24 00:12:42 +00:00
|
|
|
not(|i| context.check_exit_matcher(i))(input)?;
|
2023-03-25 14:45:43 +00:00
|
|
|
|
|
|
|
let plain_text_matcher = parser_with_context!(plain_text)(context);
|
|
|
|
|
|
|
|
map(plain_text_matcher, Object::PlainText)(input)
|
|
|
|
}
|