55 lines
1.2 KiB
Rust
55 lines
1.2 KiB
Rust
// fn test_context() {
|
|
// let foo = "foo";
|
|
// let context = ContextTree::new();
|
|
// let child1_context = PreviousElementNode { dummy: foo };
|
|
// let child1 = context.with_additional_node(&child1_context);
|
|
// let child2_context = FailMatcherNode {
|
|
// fail_matcher: ChainBehavior::AndParent(Some(&recognize_bold_end)),
|
|
// };
|
|
// 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>),
|
|
}
|