#[derive(Debug, Clone, PartialEq)]
pub struct Program {
pub body: Vec<TopLevel>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum TopLevel {
NodeDef(NodeDef),
FunctionDecl(FunctionDecl),
VarDecl(VarDecl),
ConstDecl(ConstDecl),
EnumDef(EnumDef),
EventDef(EventDef),
TimelineDef(TimelineDef),
}
#[derive(Debug, Clone, PartialEq)]
pub struct NodeDef {
pub name: String,
pub name_span: Option<(usize, usize)>,
pub body: Vec<NodeStmt>,
pub jump: Option<NodeJump>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum NodeStmt {
Text(String),
InterpolatedText(InterpolatedString),
Line(String),
InterpolatedLine(InterpolatedString),
Choice(Vec<ChoiceItem>),
Branch(BranchDef),
IfElse(IfElseStmt),
Run(RunStmt),
WithEvents(WithEventsStmt),
VarDecl(VarDecl),
Assignment(Assignment),
}
#[derive(Debug, Clone, PartialEq)]
pub struct IfElseStmt {
pub condition: IfCondition,
pub then_body: Vec<NodeStmt>,
pub else_body: Option<Vec<NodeStmt>>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum IfCondition {
Binary(Box<BinaryCondition>),
Unary(Box<UnaryCondition>),
Identifier(String),
EnumMember(String, String), Literal(bool),
FuncCall(FuncCall),
}
#[derive(Debug, Clone, PartialEq)]
pub struct BinaryCondition {
pub left: IfCondition,
pub operator: ComparisonOp,
pub right: IfCondition,
}
#[derive(Debug, Clone, PartialEq)]
pub struct UnaryCondition {
pub operator: UnaryOp,
pub operand: IfCondition,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ComparisonOp {
Greater, Less, GreaterEqual, LessEqual, Equal, NotEqual, And, Or, }
#[derive(Debug, Clone, PartialEq)]
pub enum UnaryOp {
Not, }
#[derive(Debug, Clone, PartialEq)]
pub struct InterpolatedString {
pub parts: Vec<StringPart>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum StringPart {
Text(String),
Expression(FuncCall),
Placeholder(String), }
#[derive(Debug, Clone, PartialEq)]
pub struct BranchDef {
pub name: String, pub name_span: Option<(usize, usize)>,
pub enum_type: Option<String>, pub cases: Vec<BranchCase>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct BranchCase {
pub condition: String, pub text: String,
pub events: Option<Vec<Event>>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum NodeJump {
Identifier(String, Option<(usize, usize)>),
Return,
Break,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Event {
pub index: f64,
pub action: EventAction,
}
#[derive(Debug, Clone, PartialEq)]
pub struct EventAction {
pub call: FuncCall,
pub chains: Vec<FuncCall>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct EventDef {
pub name: String,
pub name_span: Option<(usize, usize)>,
pub index: Option<f64>,
pub action: EventAction,
pub duration: Option<f64>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TimelineDef {
pub name: String,
pub name_span: Option<(usize, usize)>,
pub body: Vec<TimelineStmt>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum TimelineStmt {
Run(RunStmt),
Wait(f64),
}
#[derive(Debug, Clone, PartialEq)]
pub struct RunStmt {
pub event_name: String,
pub event_name_span: Option<(usize, usize)>,
pub args: Vec<Arg>,
pub index_override: Option<IndexOverride>,
pub ignore_duration: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum IndexOverride {
Value(f64),
Variable(String),
}
#[derive(Debug, Clone, PartialEq)]
pub struct WithEventsStmt {
pub events: Vec<WithEventItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum WithEventItem {
EventRef(String, Option<(usize, usize)>),
EventRefWithOverride(String, Option<(usize, usize)>, IndexOverride), InlineEvent(Event),
EventList(Vec<WithEventItem>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct ChoiceItem {
pub text: String,
pub condition: Option<Condition>,
pub target: ChoiceDest,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Condition {
Identifier(String),
FuncCall(FuncCall),
}
#[derive(Debug, Clone, PartialEq)]
pub enum ChoiceDest {
Identifier(String, Option<(usize, usize)>),
Return,
Break,
NestedChoices(Vec<ChoiceItem>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct FunctionDecl {
pub name: String,
pub name_span: Option<(usize, usize)>,
pub params: Vec<Param>,
pub return_type: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Param {
pub name: String,
pub type_name: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FuncCall {
pub name: String,
pub name_span: Option<(usize, usize)>,
pub args: Vec<Arg>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Arg {
String(String),
Number(f64),
Boolean(bool),
Identifier(String),
FuncCall(Box<FuncCall>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct VarDecl {
pub name: String,
pub name_span: Option<(usize, usize)>,
pub type_name: String,
pub value: Option<VarValue>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ConstDecl {
pub is_public: bool,
pub name: String,
pub name_span: Option<(usize, usize)>,
pub type_name: String,
pub value: VarValue,
}
#[derive(Debug, Clone, PartialEq)]
pub struct EnumDef {
pub name: String,
pub name_span: Option<(usize, usize)>,
pub variants: Vec<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum VarValue {
String(String),
Number(f64),
Boolean(bool),
Branch(BranchValue),
EnumMember(String, String), }
#[derive(Debug, Clone, PartialEq)]
pub struct Assignment {
pub var_name: String,
pub var_name_span: Option<(usize, usize)>,
pub value: AssignValue,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AssignValue {
EnumMember(String, String), Identifier(String),
Number(f64),
Boolean(bool),
String(String),
}
#[derive(Debug, Clone, PartialEq)]
pub struct BranchValue {
pub enum_type: Option<String>, pub cases: Vec<BranchCase>,
}