organic/src/parser/object.rs

160 lines
3.3 KiB
Rust
Raw Normal View History

2023-03-23 21:51:49 +00:00
use super::source::Source;
2023-03-23 21:02:08 +00:00
#[derive(Debug, PartialEq)]
pub enum Object<'s> {
RegularLink(RegularLink<'s>),
RadioLink(RadioLink<'s>),
RadioTarget(RadioTarget<'s>),
2023-07-13 22:18:07 +00:00
PlainLink(PlainLink<'s>),
Bold(Bold<'s>),
Italic(Italic<'s>),
Underline(Underline<'s>),
StrikeThrough(StrikeThrough<'s>),
Code(Code<'s>),
Verbatim(Verbatim<'s>),
PlainText(PlainText<'s>),
}
#[derive(Debug, PartialEq)]
pub struct Bold<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
pub struct Italic<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
pub struct Underline<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
pub struct StrikeThrough<'s> {
pub source: &'s str,
2023-04-22 23:34:13 +00:00
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
pub struct Code<'s> {
pub source: &'s str,
pub contents: &'s str,
}
#[derive(Debug, PartialEq)]
pub struct Verbatim<'s> {
pub source: &'s str,
pub contents: &'s str,
}
#[derive(Debug, PartialEq)]
pub struct PlainText<'s> {
pub source: &'s str,
}
#[derive(Debug, PartialEq)]
2023-03-23 21:02:08 +00:00
pub struct RegularLink<'s> {
pub source: &'s str,
}
#[derive(Debug, PartialEq)]
pub struct RadioTarget<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
pub struct RadioLink<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
2023-07-13 22:18:07 +00:00
#[derive(Debug, PartialEq)]
pub struct PlainLink<'s> {
pub source: &'s str,
pub link_type: &'s str,
pub path: &'s str,
2023-07-13 22:18:07 +00:00
}
impl<'s> Source<'s> for Object<'s> {
fn get_source(&'s self) -> &'s str {
match self {
Object::Bold(obj) => obj.source,
Object::Italic(obj) => obj.source,
Object::Underline(obj) => obj.source,
Object::StrikeThrough(obj) => obj.source,
Object::Code(obj) => obj.source,
Object::Verbatim(obj) => obj.source,
Object::PlainText(obj) => obj.source,
2023-03-23 21:02:08 +00:00
Object::RegularLink(obj) => obj.source,
Object::RadioLink(obj) => obj.source,
Object::RadioTarget(obj) => obj.source,
2023-07-13 22:18:07 +00:00
Object::PlainLink(obj) => obj.source,
}
}
}
2023-04-23 00:48:01 +00:00
impl<'s> Source<'s> for Bold<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
impl<'s> Source<'s> for Italic<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
impl<'s> Source<'s> for Underline<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
impl<'s> Source<'s> for StrikeThrough<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
impl<'s> Source<'s> for Code<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
impl<'s> Source<'s> for Verbatim<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
impl<'s> Source<'s> for RegularLink<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
impl<'s> Source<'s> for RadioLink<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
impl<'s> Source<'s> for RadioTarget<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
2023-07-13 22:18:07 +00:00
impl<'s> Source<'s> for PlainLink<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}