lucene_query_syntax/
ast.rs1#[derive(Debug, Clone, Eq, PartialEq)]
2pub enum Operator {
3 And,
4 Or,
5}
6
7#[derive(Debug, Clone, Eq, PartialEq)]
8pub enum Node {
9 Default(Value),
10 Named { key: String, value: Value },
11 Expression(String),
12 Negated(Box<Node>),
13 Combined {
14 left: Box<Node>,
15 right: Box<Node>,
16 operator: Operator,
17 },
18}
19
20impl Node {
21 pub fn visit<T>(self, visitor: impl Fn(Node, &dyn Fn(Box<Node>) -> T) -> T) -> T {
22 #[inline(always)]
23 fn inner<T>(node: Node, visitor: &dyn Fn(Node, &dyn Fn(Box<Node>) -> T) -> T) -> T {
24 visitor(node, &|node| node.visit(visitor))
25 }
26
27 inner(self, &visitor)
28 }
29}
30
31#[derive(Debug, Clone, Eq, PartialEq)]
32pub enum Primitive {
33 Text(String),
34 Integer(i64),
35 Boolean(bool),
36}
37
38impl From<String> for Primitive {
39 fn from(value: String) -> Self {
40 Self::Text(value)
41 }
42}
43
44impl From<i64> for Primitive {
45 fn from(value: i64) -> Self {
46 Self::Integer(value)
47 }
48}
49
50impl From<bool> for Primitive {
51 fn from(value: bool) -> Self {
52 Self::Boolean(value)
53 }
54}
55
56#[derive(Debug, Clone, Eq, PartialEq)]
57pub enum Value {
58 Primitive(Primitive),
59 Range(Boundary, Boundary),
60}
61
62impl<T: Into<Primitive>> From<T> for Value {
63 fn from(value: T) -> Self {
64 Value::Primitive(value.into())
65 }
66}
67
68#[derive(Debug, Clone, Eq, PartialEq)]
69pub enum BoundaryKind {
70 Inclusive,
71 Exclusive,
72}
73
74#[derive(Debug, Clone, Eq, PartialEq)]
75pub struct Boundary {
76 pub value: i64,
77 pub kind: BoundaryKind,
78}