use super::*;
#[derive(Debug, Clone)]
pub enum Action {
Talk { text: String, span: Span },
WordRef { name: String, span: Span },
VarRef {
name: String,
scope: VarScope,
span: Span,
},
FnCall {
name: String,
args: Args,
scope: FnScope,
span: Span,
},
SakuraScript { script: String, span: Span },
Escape { sequence: String, span: Span },
}
#[derive(Debug, Clone)]
pub struct CodeBlock {
pub language: Option<String>,
pub content: String,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct VarSet {
pub name: Option<String>,
pub scope: VarScope,
pub value: SetValue,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq)]
pub enum CallTarget {
Static(String),
Dynamic(Expr),
}
#[derive(Debug, Clone)]
pub struct CallScene {
pub target: CallTarget,
pub args: Option<Args>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct Attr {
pub key: String,
pub value: AttrValue,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AttrValue {
Integer(i64),
Float(f64),
String(String),
AttrString(String),
}
impl std::fmt::Display for AttrValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
AttrValue::Integer(v) => write!(f, "{}", v),
AttrValue::Float(v) => write!(f, "{}", v),
AttrValue::String(v) => write!(f, "{}", v),
AttrValue::AttrString(v) => write!(f, "{}", v),
}
}
}
#[derive(Debug, Clone)]
pub struct KeyWords {
pub names: Vec<String>,
pub words: Vec<String>,
pub span: Span,
}
impl KeyWords {
pub fn name(&self) -> &str {
&self.names[0]
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Args {
pub items: Vec<Arg>,
pub span: Span,
}
impl Args {
pub fn empty() -> Self {
Self {
items: Vec::new(),
span: Span::default(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum Arg {
Positional(Expr),
Keyword { key: String, value: Expr },
}
#[derive(Debug, Clone, PartialEq)]
pub enum Expr {
Integer(i64),
Float(f64),
String(String),
BlankString,
VarRef { name: String, scope: VarScope },
FnCall {
name: String,
args: Args,
scope: FnScope,
},
Paren(Box<Expr>),
Binary {
op: BinOp,
lhs: Box<Expr>,
rhs: Box<Expr>,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum SetValue {
Expr(Expr),
WordRef { name: String },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VarScope {
Local,
Global,
Args(u8),
Property,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FnScope {
Local,
Global,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BinOp {
Add,
Sub,
Mul,
Div,
Mod,
}