#[derive(Debug, Clone)]
pub struct Document {
pub items: Vec<DocumentItem>,
}
impl Document {
pub fn patterns(&self) -> Vec<&PatternAst> {
self.items
.iter()
.filter_map(|i| match i {
DocumentItem::Pattern(p) => Some(p),
_ => None,
})
.collect()
}
pub fn graphs(&self) -> Vec<&GraphAst> {
self.items
.iter()
.filter_map(|i| match i {
DocumentItem::Graph(g) => Some(g),
_ => None,
})
.collect()
}
}
#[derive(Debug, Clone)]
pub enum DocumentItem {
Pattern(PatternAst),
Graph(GraphAst),
Compose(ComposeAst),
}
#[derive(Debug, Clone)]
pub struct ComposeAst {
pub name: String,
pub body: ComposeBody,
}
#[derive(Debug, Clone)]
pub enum ComposeBody {
Sequence {
left: String,
right: String,
shared: Vec<String>,
},
Choice {
alternatives: Vec<String>,
exclusive: bool,
},
Repeat {
pattern: String,
min: usize,
max: Option<usize>,
shared: Vec<String>,
},
}
#[derive(Debug, Clone)]
pub struct PatternAst {
pub name: String,
pub stages: Vec<StageAst>,
pub negations: Vec<NegationAst>,
pub temporals: Vec<TemporalAst>,
pub metadata: Vec<(String, String)>,
pub deadline: Option<f64>,
pub unordered_groups: Vec<Vec<usize>>,
pub private: bool,
}
#[derive(Debug, Clone)]
pub struct PatternBody {
pub stages: Vec<StageAst>,
pub negations: Vec<NegationAst>,
pub temporals: Vec<TemporalAst>,
pub metadata: Vec<(String, String)>,
pub deadline: Option<f64>,
pub unordered_groups: Vec<Vec<usize>>,
pub private: bool,
}
#[derive(Debug, Clone)]
pub struct StageAst {
pub anchor: String,
pub clauses: Vec<ClauseAst>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SourceKind {
Var,
Literal,
}
#[derive(Debug, Clone)]
pub struct ClauseAst {
pub source: String,
pub source_kind: SourceKind,
pub label: String,
pub target: ClauseTarget,
pub negated: bool,
}
#[derive(Debug, Clone)]
pub enum ClauseTarget {
LiteralStr(String),
LiteralNum(f64),
LiteralBool(bool),
Bind(String),
NodeRef(String),
Constraint(ConstraintOp, ConstraintValue),
ConstraintVar(ConstraintOp, String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConstraintOp {
Eq,
Lt,
Gt,
Lte,
Gte,
}
#[derive(Debug, Clone)]
pub enum ConstraintValue {
Num(f64),
Str(String),
}
#[derive(Debug, Clone)]
pub struct NegationAst {
pub kind: NegationKind,
pub clauses: Vec<ClauseAst>,
}
#[derive(Debug, Clone)]
pub enum NegationKind {
Between(String, String),
After(String),
Global,
}
#[derive(Debug, Clone)]
pub struct TemporalAst {
pub left: String,
pub relation: String,
pub right: String,
pub gap_min: Option<f64>,
pub gap_max: Option<f64>,
}
#[derive(Debug, Clone)]
pub struct GraphAst {
pub edges: Vec<EdgeAst>,
pub now: Option<i64>,
}
#[derive(Debug, Clone)]
pub struct EdgeAst {
pub time_start: i64,
pub time_end: Option<i64>,
pub source: String,
pub label: String,
pub target: EdgeTarget,
}
#[derive(Debug, Clone)]
pub enum EdgeTarget {
Str(String),
Num(f64),
Bool(bool),
NodeRef(String),
}