1use std::collections::HashMap;
2
3use uni_cypher::ast::{Clause, Pattern, Query};
4use uni_cypher::locy_ast::{
5 AbduceQuery, AlongBinding, BestByClause, DeriveCommand, ExplainRule, FoldBinding, GoalQuery,
6 RuleCondition, RuleOutput,
7};
8
9#[derive(Debug, Clone)]
11pub struct CompiledProgram {
12 pub strata: Vec<Stratum>,
13 pub rule_catalog: HashMap<String, CompiledRule>,
14 pub warnings: Vec<CompilerWarning>,
15 pub commands: Vec<CompiledCommand>,
16}
17
18#[derive(Debug, Clone)]
20pub enum CompiledCommand {
21 GoalQuery(GoalQuery),
22 Assume(CompiledAssume),
23 Abduce(AbduceQuery),
24 ExplainRule(ExplainRule),
25 DeriveCommand(DeriveCommand),
26 Cypher(Query),
27}
28
29#[derive(Debug, Clone)]
31pub struct CompiledAssume {
32 pub mutations: Vec<Clause>,
33 pub body_program: CompiledProgram,
34 pub body_commands: Vec<CompiledCommand>,
35}
36
37#[derive(Debug, Clone)]
39pub struct Stratum {
40 pub id: usize,
41 pub rules: Vec<CompiledRule>,
42 pub is_recursive: bool,
43 pub depends_on: Vec<usize>,
44}
45
46#[derive(Debug, Clone)]
48pub struct CompiledRule {
49 pub name: String,
50 pub clauses: Vec<CompiledClause>,
51 pub yield_schema: Vec<YieldColumn>,
52 pub priority: Option<i64>,
53}
54
55#[derive(Debug, Clone)]
57pub struct CompiledClause {
58 pub match_pattern: Pattern,
59 pub where_conditions: Vec<RuleCondition>,
60 pub along: Vec<AlongBinding>,
61 pub fold: Vec<FoldBinding>,
62 pub best_by: Option<BestByClause>,
63 pub output: RuleOutput,
64 pub priority: Option<i64>,
65}
66
67#[derive(Debug, Clone, PartialEq)]
69pub struct YieldColumn {
70 pub name: String,
71 pub is_key: bool,
72}
73
74#[derive(Debug, Clone)]
76pub struct CompilerWarning {
77 pub code: WarningCode,
78 pub message: String,
79 pub rule_name: String,
80}
81
82#[derive(Debug, Clone, PartialEq)]
83pub enum WarningCode {
84 MsumNonNegativity,
85}