organic/src/parser/token.rs

131 lines
2.3 KiB
Rust
Raw Normal View History

2022-12-04 04:53:52 +00:00
#[derive(Debug)]
pub enum Token<'a> {
TextElement(TextElement<'a>),
Paragraph(Paragraph<'a>),
2022-12-04 04:53:52 +00:00
}
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
}
}
2022-12-18 08:29:01 +00:00
#[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,
}
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
}
}