use serde::Serialize; use super::*; #[derive(Debug, Clone, Serialize)] pub enum Expression { Literal(Literal), Path(ExprPath), Statement(Box), Array(Vec), ArrayRepeat(Box, Box), Closure { return_type: Option, params: Vec, body: 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), } #[derive(Debug, Clone, Serialize)] pub enum Pattern { NamedTuple(Path, Vec>), Struct(Path, Vec>)>>), Tuple(Vec>), Literal(Literal), Path(bool, Path), Etc, } #[derive(Debug, Clone, Serialize)] pub enum MacroDelimiter { Paren, Bracket, Brace, } #[derive(Debug, Clone, Serialize)] pub enum Postfix { FieldAccess(Identifier, Option), TupleFieldAccess(u8, Option), Call(Vec), MacroCall { inner: String, delimiter: MacroDelimiter, }, StructCall(Vec<(Identifier, Option)>), Assign(String, Box), Index(Expression), As(TypeExpr), Increment, Decrement, Try, } #[derive(Debug, Clone, Serialize)] pub enum Prefix { Ref, RefMut, Deref, Not, Neg, } #[derive(Debug, Clone, Serialize, PartialEq, Eq, Hash)] pub struct ExprPathSegment { pub ident: Identifier, pub generics: Option, } #[derive(Debug, Clone, Serialize, PartialEq, Eq, Hash)] pub struct ExprPath(pub Vec); #[derive(Debug, Clone, Serialize, PartialEq, Eq, Hash)] pub struct Generics(pub Vec); #[derive(Debug, Clone, Serialize, PartialEq, Eq, Hash)] 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 } } } impl From for ExprPath { fn from(path: Path) -> Self { Self( path.0 .into_iter() .map(|v| ExprPathSegment { ident: v, generics: None, }) .collect(), ) } }