Skip to main content

marsdb_query/
ast.rs

1#[derive(Debug, Clone, PartialEq)]
2pub enum Literal {
3    Int(i64),
4    Float(f64),
5    String(String),
6    Bool(bool),
7    Null,
8}
9
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct PropAccess {
12    pub var: String,
13    pub prop: String,
14}
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum CompareOp {
18    Eq,
19    Ne,
20    Lt,
21    Le,
22    Gt,
23    Ge,
24}
25
26#[derive(Debug, Clone)]
27pub enum Expr {
28    And(Box<Expr>, Box<Expr>),
29    Or(Box<Expr>, Box<Expr>),
30    Not(Box<Expr>),
31    Compare(PropAccess, CompareOp, Literal),
32}
33
34#[derive(Debug, Clone)]
35pub enum ReturnExpr {
36    Var(String),
37    Prop(PropAccess),
38    Lit(Literal),
39}
40
41#[derive(Debug, Clone)]
42pub struct ReturnItem {
43    pub expr: ReturnExpr,
44    pub alias: Option<String>,
45}
46
47#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48pub enum RelDirection {
49    /// (a)-[..]->(b)
50    Right,
51    /// (a)<-[..]-(b)
52    Left,
53}
54
55#[derive(Debug, Clone)]
56pub struct NodePattern {
57    pub var: Option<String>,
58    pub label: Option<String>,
59    pub props: Vec<(String, Literal)>,
60}
61
62#[derive(Debug, Clone)]
63pub struct RelPattern {
64    pub var: Option<String>,
65    pub rel_type: Option<String>,
66    #[allow(dead_code)] // property-map on relationships parsed but not filtered on in v1
67    pub props: Vec<(String, Literal)>,
68    pub direction: RelDirection,
69}
70
71/// A linear chain: node, (rel, node)*.
72#[derive(Debug, Clone)]
73pub struct Pattern {
74    pub start: NodePattern,
75    pub hops: Vec<(RelPattern, NodePattern)>,
76}
77
78#[derive(Debug, Clone)]
79pub enum Tail {
80    Return(Vec<ReturnItem>),
81    Delete(Vec<String>),
82    DetachDelete(Vec<String>),
83    Set(Vec<(PropAccess, Literal)>),
84}
85
86#[derive(Debug, Clone)]
87pub enum Statement {
88    Create(Vec<Pattern>),
89    Match {
90        pattern: Pattern,
91        where_clause: Option<Expr>,
92        tail: Tail,
93        limit: Option<i64>,
94    },
95}