organic/trash/token.rs
2023-03-25 12:25:05 -04:00

137 lines
2.5 KiB
Rust

#[derive(Debug)]
pub enum Token<'a> {
TextElement(TextElement<'a>),
Paragraph(Paragraph<'a>),
}
impl<'a> Into<Token<'a>> for TextElement<'a> {
fn into(self) -> Token<'a> {
Token::TextElement(self)
}
}
impl<'a> Into<Token<'a>> for Paragraph<'a> {
fn into(self) -> Token<'a> {
Token::Paragraph(self)
}
}
#[derive(Debug)]
pub enum TextElement<'a> {
Span(Span<'a>),
Space(Space<'a>),
LineBreak(LineBreak<'a>),
Symbol(Symbol<'a>),
Bold(Bold<'a>),
Link(Link<'a>),
}
#[derive(Debug)]
pub struct Span<'a> {
pub source: &'a str,
}
#[derive(Debug)]
pub struct Space<'a> {
pub source: &'a str,
}
#[derive(Debug)]
pub struct LineBreak<'a> {
pub source: &'a str,
}
#[derive(Debug)]
pub struct Symbol<'a> {
pub source: &'a str,
}
#[derive(Debug)]
pub struct BlankLine<'a> {
pub source: &'a str,
}
#[derive(Debug)]
pub struct Sequence<'a> {
pub source: &'a str,
}
#[derive(Debug)]
pub struct Bold<'a> {
pub source: &'a str,
}
#[derive(Debug)]
pub struct Link<'a> {
pub source: &'a str,
}
#[derive(Debug)]
pub struct Paragraph<'a> {
pub source: &'a str,
pub contents: Vec<TextElement<'a>>,
pub paragraph_end: &'a str,
}
pub trait Source<'a> {
fn get_source(&'a self) -> &'a str;
}
impl<'a> Source<'a> for TextElement<'a> {
fn get_source(&'a self) -> &'a str {
match self {
TextElement::Span(elem) => elem.source,
TextElement::Space(elem) => elem.source,
TextElement::LineBreak(elem) => elem.source,
TextElement::Symbol(elem) => elem.source,
TextElement::Bold(elem) => elem.source,
TextElement::Link(elem) => elem.source,
}
}
}
impl<'a> Source<'a> for Paragraph<'a> {
fn get_source(&'a self) -> &'a str {
self.source
}
}
#[derive(Debug)]
pub struct PlainList<'a> {
pub source: &'a str,
}
impl<'a> Source<'a> for PlainList<'a> {
fn get_source(&'a self) -> &'a str {
self.source
}
}
#[derive(Debug)]
pub struct ListItem<'a> {
pub source: &'a str,
pub leading_whitespace: &'a str,
pub bullet: &'a str,
pub counter_set: Option<&'a str>,
pub check_box: Option<&'a str>,
pub item_tag: Option<&'a str>,
pub contents: Vec<TextElement<'a>>,
}
impl<'a> Source<'a> for ListItem<'a> {
fn get_source(&'a self) -> &'a str {
self.source
}
}
#[derive(Debug)]
pub struct ListCounter<'a> {
pub source: &'a str,
}
impl<'a> Source<'a> for ListCounter<'a> {
fn get_source(&'a self) -> &'a str {
self.source
}
}