Added traits for nodes and context elements.

This commit is contained in:
Tom Alexander 2022-11-26 23:12:53 -05:00
parent f93f1c5950
commit 4a2b633f9c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 44 additions and 0 deletions

View File

@ -8,3 +8,47 @@
// };
// let child2 = child1.with_additional_node(&child2_context);
// }
use nom::error::VerboseError;
use nom::IResult;
type Matcher = dyn for<'s> Fn(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>;
type Link<'p> = Option<&'p dyn NodeType<'p>>;
struct Node<'p, T> {
data: T,
parent: Link<'p>,
}
pub trait NodeType<'p> {
fn get_data(&self) -> &dyn ContextElement;
fn get_parent(&self) -> Link<'p>;
}
impl<'p, T> NodeType<'p> for Node<'p, T>
where
T: ContextElement,
{
fn get_data(&self) -> &dyn ContextElement {
&self.data
}
fn get_parent(&self) -> Link<'p> {
self.parent
}
}
pub trait ContextElement {}
struct FailMatcherNode<'r> {
fail_matcher: ChainBehavior<'r>,
}
struct PreviousElementNode<'r> {
dummy: &'r str,
}
enum ChainBehavior<'r> {
AndParent(Option<&'r Matcher>),
IgnoreParent(Option<&'r Matcher>),
}