use crate::Span;
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum Arg {
Obj(String),
Var(String),
Ty(String),
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Term {
pub pred: String,
pub args: Vec<Arg>,
pub span: Span,
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum Modal {
Knows,
Believes,
Safe,
Common,
KnowsDual,
BelievesDual,
SafeDual,
KnowsWhether,
BelievesWhether,
Ignorant,
Undecided,
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum Expr {
Hole(Span),
True(Span),
False(Span),
Atom(Term),
Not(Box<Expr>, Span),
And(Box<Expr>, Box<Expr>, Span),
Or(Box<Expr>, Box<Expr>, Span),
Implies(Box<Expr>, Box<Expr>, Span),
Modality {
op: Modal,
agents: Option<Vec<Arg>>,
cond: Option<Box<Expr>>,
body: Box<Expr>,
span: Span,
},
}
impl Expr {
pub fn span(&self) -> Span {
match self {
Expr::Hole(s) | Expr::True(s) | Expr::False(s) => *s,
Expr::Atom(t) => t.span,
Expr::Not(_, s) | Expr::And(_, _, s) | Expr::Or(_, _, s) | Expr::Implies(_, _, s) => *s,
Expr::Modality { span, .. } => *span,
}
}
}
#[derive(Clone, Debug)]
pub struct TypeDecl {
pub name: String,
pub parent: String,
pub span: Span,
}
#[derive(Clone, Debug)]
pub struct ObjDecl {
pub name: String,
pub ty: String,
pub span: Span,
}
#[derive(Clone, Debug)]
pub struct PropDecl {
pub name: String,
pub params: Vec<String>,
pub span: Span,
}
#[derive(Clone, Debug)]
pub struct ConstDecl {
pub negated: bool,
pub term: Term,
}
#[derive(Clone, Debug)]
pub enum Clause {
Actor(Arg, Span),
Pre(Expr),
Causes {
lits: Vec<(Term, bool)>,
cond: Option<Expr>,
span: Span,
},
Determines(Expr),
Announces(Expr),
Observes {
who: Arg,
cond: Option<Expr>,
span: Span,
},
Aware {
who: Arg,
cond: Option<Expr>,
span: Span,
},
}
#[derive(Clone, Debug)]
pub struct RuleDecl {
pub head: Term,
pub body: Vec<Term>,
pub span: Span,
}
#[derive(Clone, Debug)]
pub struct DefDecl {
pub name: String,
pub params: Vec<String>,
pub body: Expr,
pub span: Span,
}
#[derive(Clone, Debug)]
pub struct ParamDecl {
pub name: String,
pub ty: String,
pub span: Span,
}
#[derive(Clone, Debug)]
pub struct ActionDecl {
pub name: String,
pub params: Vec<ParamDecl>,
pub clauses: Vec<Clause>,
pub span: Span,
}
#[derive(Clone, Debug)]
pub struct WorldDecl {
pub name: String,
pub designated: bool,
pub facts: Vec<Term>,
pub span: Span,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Cmp {
Equi,
Lt,
Le,
}
#[derive(Clone, Debug)]
pub struct EdgeDecl {
pub agent: String,
pub from: String,
pub cmp: Cmp,
pub to: String,
pub span: Span,
}
#[derive(Clone, Debug)]
pub enum Init {
Declarative(Vec<Expr>, Span),
Explicit {
worlds: Vec<WorldDecl>,
edges: Vec<EdgeDecl>,
span: Span,
},
}
#[derive(Clone, Debug, Default)]
pub struct Ast {
pub types: Vec<TypeDecl>,
pub objects: Vec<ObjDecl>,
pub agents: Vec<(String, Span)>,
pub props: Vec<PropDecl>,
pub constants: Vec<ConstDecl>,
pub defines: Vec<DefDecl>,
pub rules: Vec<RuleDecl>,
pub init: Option<Init>,
pub goal: Option<Expr>,
pub invariants: Vec<(Expr, Span)>,
pub actions: Vec<ActionDecl>,
}