1#[derive(Debug, Clone)]
6pub struct Document {
7 pub items: Vec<DocumentItem>,
8}
9
10impl Document {
11 pub fn patterns(&self) -> Vec<&PatternAst> {
13 self.items
14 .iter()
15 .filter_map(|i| match i {
16 DocumentItem::Pattern(p) => Some(p),
17 _ => None,
18 })
19 .collect()
20 }
21
22 pub fn graphs(&self) -> Vec<&GraphAst> {
24 self.items
25 .iter()
26 .filter_map(|i| match i {
27 DocumentItem::Graph(g) => Some(g),
28 _ => None,
29 })
30 .collect()
31 }
32}
33
34#[derive(Debug, Clone)]
36pub enum DocumentItem {
37 Pattern(PatternAst),
38 Graph(GraphAst),
39 Compose(ComposeAst),
40}
41
42#[derive(Debug, Clone)]
44pub struct ComposeAst {
45 pub name: String,
46 pub body: ComposeBody,
47}
48
49#[derive(Debug, Clone)]
51pub enum ComposeBody {
52 Sequence {
54 left: String,
55 right: String,
56 shared: Vec<String>,
57 },
58 Choice {
60 alternatives: Vec<String>,
61 exclusive: bool,
62 },
63 Repeat {
65 pattern: String,
66 min: usize,
67 max: Option<usize>,
68 shared: Vec<String>,
69 },
70}
71
72#[derive(Debug, Clone)]
74pub struct PatternAst {
75 pub name: String,
76 pub stages: Vec<StageAst>,
77 pub negations: Vec<NegationAst>,
78 pub temporals: Vec<TemporalAst>,
79 pub metadata: Vec<(String, String)>,
80 pub deadline: Option<f64>,
81 pub unordered_groups: Vec<Vec<usize>>,
84 pub private: bool,
86}
87
88#[derive(Debug, Clone)]
95pub struct PatternBody {
96 pub stages: Vec<StageAst>,
97 pub negations: Vec<NegationAst>,
98 pub temporals: Vec<TemporalAst>,
99 pub metadata: Vec<(String, String)>,
100 pub deadline: Option<f64>,
101 pub unordered_groups: Vec<Vec<usize>>,
102 pub private: bool,
103}
104
105#[derive(Debug, Clone)]
107pub struct StageAst {
108 pub anchor: String,
109 pub clauses: Vec<ClauseAst>,
110}
111
112#[derive(Debug, Clone, Copy, PartialEq, Eq)]
114pub enum SourceKind {
115 Var,
117 Literal,
119}
120
121#[derive(Debug, Clone)]
123pub struct ClauseAst {
124 pub source: String,
126 pub source_kind: SourceKind,
128 pub label: String,
130 pub target: ClauseTarget,
132 pub negated: bool,
134}
135
136#[derive(Debug, Clone)]
138pub enum ClauseTarget {
139 LiteralStr(String),
141 LiteralNum(f64),
143 LiteralBool(bool),
145 Bind(String),
147 NodeRef(String),
149 Constraint(ConstraintOp, ConstraintValue),
151 ConstraintVar(ConstraintOp, String),
153}
154
155#[derive(Debug, Clone, Copy, PartialEq, Eq)]
157pub enum ConstraintOp {
158 Eq,
159 Lt,
160 Gt,
161 Lte,
162 Gte,
163}
164
165#[derive(Debug, Clone)]
167pub enum ConstraintValue {
168 Num(f64),
169 Str(String),
170}
171
172#[derive(Debug, Clone)]
174pub struct NegationAst {
175 pub kind: NegationKind,
176 pub clauses: Vec<ClauseAst>,
177}
178
179#[derive(Debug, Clone)]
181pub enum NegationKind {
182 Between(String, String),
184 After(String),
186 Global,
188}
189
190#[derive(Debug, Clone)]
192pub struct TemporalAst {
193 pub left: String,
194 pub relation: String,
195 pub right: String,
196 pub gap_min: Option<f64>,
198 pub gap_max: Option<f64>,
200}
201
202#[derive(Debug, Clone)]
204pub struct GraphAst {
205 pub edges: Vec<EdgeAst>,
206 pub now: Option<i64>,
207}
208
209#[derive(Debug, Clone)]
211pub struct EdgeAst {
212 pub time_start: i64,
213 pub time_end: Option<i64>,
215 pub source: String,
216 pub label: String,
217 pub target: EdgeTarget,
218}
219
220#[derive(Debug, Clone)]
222pub enum EdgeTarget {
223 Str(String),
225 Num(f64),
227 Bool(bool),
229 NodeRef(String),
231}