use serde::Serialize; use super::*; #[derive(Debug, Clone, Serialize)] pub enum Expression { Literal(Literal), Path(ExprPath), Statement(Box), Fix { initial: Box, prefixes: Vec, postfixes: Vec, }, Binary { lhs: Box, op: String, rhs: Box, }, } #[derive(Debug, Clone, Serialize)] pub enum Literal { String(String), Int(i64), Float(f64), Bool(bool), Tuple(Vec), Array(Vec), ArrayRepeat(Box, Box), } #[derive(Debug, Clone, Serialize)] pub enum Pattern { NamedTuple(Path, Vec>), Struct(Path, Vec>), Tuple(Vec>), Literal(Literal), Path(bool, Path), } #[derive(Debug, Clone, Serialize)] pub enum Postfix { FieldAccess(Identifier, Option), Call(Vec), MacroCall(String), StructCall(Vec<(Identifier, Expression)>), Assign(String, Box), Index(Expression), As(TypeExpr), Increment, Decrement, Try, } #[derive(Debug, Clone, Serialize)] pub enum Prefix { Ref, RefMut, Deref, Not, Neg, Closure(Option, Vec), } #[derive(Debug, Clone, Serialize)] pub struct ExprPathSegment { pub ident: Identifier, pub generics: Option, } #[derive(Debug, Clone, Serialize)] pub struct ExprPath(pub Vec); #[derive(Debug, Clone, Serialize)] pub struct Generics(pub Vec); #[derive(Debug, Clone, Serialize)] pub enum Generic { Lifetime(Identifier), Type(TypeExpr), } impl Expression { pub fn is_block(&self) -> bool { if let Expression::Statement(stmt) = self { stmt.is_block() } else { false } } }