Added traits for nodes and context elements.
This commit is contained in:
parent
f93f1c5950
commit
4a2b633f9c
@ -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>),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user