Move the structs into the token module.

This commit is contained in:
Tom Alexander 2022-12-18 03:24:35 -05:00
parent 8211e1043f
commit 2def475337
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 70 additions and 69 deletions

View File

@ -1,5 +1,3 @@
use crate::parser::parser_with_context::parser_with_context;
use super::combinator::context_many_till;
use super::error::CustomError;
use super::error::MyError;
@ -9,11 +7,12 @@ use super::parser_context::ContextElement;
use super::parser_context::ExitMatcherNode;
use super::text::symbol;
use super::text::text_element;
use super::text::Bold;
use super::text::TextElement;
use super::token::Bold;
use super::token::TextElement;
use super::token::Token;
use super::util::in_section;
use super::Context;
use crate::parser::parser_with_context::parser_with_context;
use nom::branch::alt;
use nom::bytes::complete::tag;
use nom::combinator::map;

View File

@ -2,9 +2,8 @@
use super::combinator::context_many1;
use super::error::Res;
use super::paragraph::paragraph;
use super::parser_context::ContextElement;
use super::parser_context::ContextTree;
use super::text::Paragraph;
use super::token::Paragraph;
use super::token::Token;
use super::Context;
use nom::IResult;

View File

@ -9,8 +9,8 @@ use super::parser_context::ContextElement;
use super::parser_context::ExitMatcherNode;
use super::text::symbol;
use super::text::text_element;
use super::text::Link;
use super::text::TextElement;
use super::token::Link;
use super::token::TextElement;
use super::util::in_section;
use super::Context;
use nom::combinator::map;

View File

@ -6,8 +6,8 @@ use super::parser_context::ExitMatcherNode;
use super::text::blank_line;
use super::text::line_break;
use super::text::text_element;
use super::text::Paragraph;
use super::text::TextElement;
use super::token::Paragraph;
use super::token::TextElement;
use super::token::Token;
use super::Context;
use nom::branch::alt;

View File

@ -12,64 +12,14 @@ use super::bold::bold;
use super::error::Res;
use super::link::link;
use super::parser_with_context::parser_with_context;
use super::token::BlankLine;
use super::token::LineBreak;
use super::token::Space;
use super::token::Span;
use super::token::Symbol;
use super::token::TextElement;
use super::Context;
#[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> {
contents: &'a str,
}
#[derive(Debug)]
pub struct Space<'a> {
contents: &'a str,
}
#[derive(Debug)]
pub struct LineBreak<'a> {
contents: &'a str,
}
#[derive(Debug)]
pub struct Symbol<'a> {
contents: &'a str,
}
#[derive(Debug)]
pub struct BlankLine<'a> {
contents: &'a str,
}
#[derive(Debug)]
pub struct Sequence<'a> {
pub contents: &'a str,
}
#[derive(Debug)]
pub struct Bold<'a> {
pub contents: &'a str,
}
#[derive(Debug)]
pub struct Link<'a> {
pub contents: &'a str,
}
#[derive(Debug)]
pub struct Paragraph<'a> {
pub contents: Vec<TextElement<'a>>,
pub paragraph_end: &'a str,
}
pub fn line_break(input: &str) -> Res<&str, LineBreak> {
map(line_ending, |s: &str| LineBreak { contents: s })(input)
}

View File

@ -1,6 +1,3 @@
use super::text::Paragraph;
use super::text::TextElement;
#[derive(Debug)]
pub enum Token<'a> {
TextElement(TextElement<'a>),
@ -18,3 +15,59 @@ impl<'a> Into<Token<'a>> for Paragraph<'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 contents: &'a str,
}
#[derive(Debug)]
pub struct Space<'a> {
pub contents: &'a str,
}
#[derive(Debug)]
pub struct LineBreak<'a> {
pub contents: &'a str,
}
#[derive(Debug)]
pub struct Symbol<'a> {
pub contents: &'a str,
}
#[derive(Debug)]
pub struct BlankLine<'a> {
pub contents: &'a str,
}
#[derive(Debug)]
pub struct Sequence<'a> {
pub contents: &'a str,
}
#[derive(Debug)]
pub struct Bold<'a> {
pub contents: &'a str,
}
#[derive(Debug)]
pub struct Link<'a> {
pub contents: &'a str,
}
#[derive(Debug)]
pub struct Paragraph<'a> {
pub contents: Vec<TextElement<'a>>,
pub paragraph_end: &'a str,
}