Start writing the parser for headings.

This commit is contained in:
Tom Alexander
2023-03-23 19:35:32 -04:00
parent d3c804942f
commit 5c8a064eca
4 changed files with 101 additions and 8 deletions

View File

@@ -7,7 +7,6 @@ use super::error::MyError;
use super::error::Res;
use super::list::List;
use super::list::Node;
use super::token::Token;
use super::Context;
type Matcher = dyn for<'r, 's> Fn(Context<'r, 's>, &'s str) -> Res<&'s str, &'s str>;
@@ -90,13 +89,25 @@ impl<'r, 's> ContextTree<'r, 's> {
// TODO: Make this a specific error instead of just a generic MyError
return Err(nom::Err::Error(CustomError::MyError(MyError("NoExit"))));
}
pub fn get_document_root(&self) -> Option<&'s str> {
for current_node in self.iter() {
let context_element = current_node.get_data();
match context_element {
ContextElement::DocumentRoot(body) => {
return Some(body);
}
_ => {}
}
}
None
}
}
#[derive(Debug)]
pub enum ContextElement<'r, 's> {
DocumentRoot(&'s str),
ExitMatcherNode(ExitMatcherNode<'r>),
PreviousElementNode(PreviousElementNode<'s>),
Context(&'r str),
ListItem(usize),
StartOfParagraph,
@@ -107,11 +118,6 @@ pub struct ExitMatcherNode<'r> {
pub exit_matcher: ChainBehavior<'r>,
}
#[derive(Debug)]
pub struct PreviousElementNode<'r> {
pub element: Token<'r>,
}
#[derive(Clone)]
pub enum ChainBehavior<'r> {
AndParent(Option<&'r Matcher>),