lucene-query-syntax 0.1.0

Parses a subset of the Apache Lucene query syntax
Documentation
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Operator {
    And,
    Or,
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Node {
    Default(Value),
    Named { key: String, value: Value },
    Expression(String),
    Negated(Box<Node>),
    Combined {
        left: Box<Node>,
        right: Box<Node>,
        operator: Operator,
    },
}

impl Node {
    pub fn visit<T>(self, visitor: impl Fn(Node, &dyn Fn(Box<Node>) -> T) -> T) -> T {
        #[inline(always)]
        fn inner<T>(node: Node, visitor: &dyn Fn(Node, &dyn Fn(Box<Node>) -> T) -> T) -> T {
            visitor(node, &|node| node.visit(visitor))
        }
        
        inner(self, &visitor)
    }
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Primitive {
    Text(String),
    Integer(i64),
    Boolean(bool),
}

impl From<String> for Primitive {
    fn from(value: String) -> Self {
        Self::Text(value)
    }
}

impl From<i64> for Primitive {
    fn from(value: i64) -> Self {
        Self::Integer(value)
    }
}

impl From<bool> for Primitive {
    fn from(value: bool) -> Self {
        Self::Boolean(value)
    }
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Value {
    Primitive(Primitive),
    Range(Boundary, Boundary),
}

impl<T: Into<Primitive>> From<T> for Value {
    fn from(value: T) -> Self {
        Value::Primitive(value.into())
    }
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum BoundaryKind {
    Inclusive,
    Exclusive,
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Boundary {
    pub value: i64,
    pub kind: BoundaryKind,
}