2023-03-23 21:59:39 +00:00
|
|
|
use crate::parser::parser_context::ContextElement;
|
|
|
|
use crate::parser::parser_context::ContextTree;
|
|
|
|
|
2023-03-23 21:51:49 +00:00
|
|
|
use super::element::Element;
|
2023-03-23 21:59:39 +00:00
|
|
|
use super::error::Res;
|
2023-03-23 21:51:49 +00:00
|
|
|
use super::source::Source;
|
2022-10-15 00:17:48 +00:00
|
|
|
|
2023-03-23 21:51:49 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Document<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
pub zeroth_section: Option<Section<'s>>,
|
|
|
|
pub children: Vec<Heading<'s>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Heading<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
pub children: Vec<DocumentElement<'s>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Section<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
pub children: Vec<Element<'s>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum DocumentElement<'s> {
|
|
|
|
Heading(Heading<'s>),
|
|
|
|
Section(Section<'s>),
|
|
|
|
}
|
2022-12-04 03:44:53 +00:00
|
|
|
|
2023-03-23 21:51:49 +00:00
|
|
|
impl<'s> Source<'s> for Document<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
self.source
|
|
|
|
}
|
|
|
|
}
|
2022-12-18 09:22:28 +00:00
|
|
|
|
2023-03-23 21:51:49 +00:00
|
|
|
impl<'s> Source<'s> for DocumentElement<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
match self {
|
|
|
|
DocumentElement::Heading(obj) => obj.source,
|
|
|
|
DocumentElement::Section(obj) => obj.source,
|
|
|
|
}
|
|
|
|
}
|
2022-11-27 00:14:19 +00:00
|
|
|
}
|
2023-03-23 21:59:39 +00:00
|
|
|
|
|
|
|
pub fn document(input: &str) -> Res<&str, Document> {
|
|
|
|
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
|
|
|
let document_context =
|
|
|
|
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
|
|
|
|
|
|
|
|
todo!()
|
|
|
|
}
|