organic/src/parser/nom_context.rs

45 lines
832 B
Rust
Raw Normal View History

2022-10-15 00:01:37 -04:00
use std::cell::RefCell;
use std::rc::Rc;
2022-07-16 17:27:08 -04:00
use nom::branch::alt;
use nom::combinator::not;
2022-07-15 23:26:49 -04:00
use nom::error::VerboseError;
use nom::IResult;
2022-10-15 00:01:37 -04:00
use nom::Parser;
2022-11-24 14:59:37 -05:00
type Link<T> = Option<Box<Node<T>>>;
type Matcher = dyn for<'s> Fn(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>;
struct Node<T> {
elem: T,
next: Link<T>,
}
pub struct List<T> {
head: Link<T>,
}
impl<T> List<T> {
pub fn new() -> Self {
List { head: None }
}
pub fn push(&mut self, element: T) {
let new_node = Box::new(Node {
elem: element,
next: self.head.take(),
});
self.head = Some(new_node);
}
}
struct ContextElement<'r> {
fail_matcher: ChainBehavior<'r>,
}
enum ChainBehavior<'r> {
AndParent(Option<&'r Matcher>),
IgnoreParent(Option<&'r Matcher>),
}