use crate::common::spans::Span; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[serde(tag = "kind")] pub enum Node { File(FileNode), Import(ImportNode), ImportSpec(ImportSpecNode), ServiceDecl(ServiceDeclNode), ServiceFnSig(ServiceFnSigNode), FnDecl(FnDeclNode), TypeDecl(TypeDeclNode), TypeBody(TypeBodyNode), Block(BlockNode), LetStmt(LetStmtNode), ExprStmt(ExprStmtNode), ReturnStmt(ReturnStmtNode), IntLit(IntLitNode), FloatLit(FloatLitNode), BoundedLit(BoundedLitNode), StringLit(StringLitNode), Ident(IdentNode), Call(CallNode), Unary(UnaryNode), Binary(BinaryNode), Cast(CastNode), IfExpr(IfExprNode), WhenExpr(WhenExprNode), WhenArm(WhenArmNode), TypeName(TypeNameNode), TypeApp(TypeAppNode), Alloc(AllocNode), Mutate(MutateNode), Borrow(BorrowNode), Peek(PeekNode), MemberAccess(MemberAccessNode), } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct FileNode { pub span: Span, pub imports: Vec, pub decls: Vec, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct ImportNode { pub span: Span, pub spec: Box, // Must be ImportSpec pub from: String, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct ImportSpecNode { pub span: Span, pub path: Vec, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct ServiceDeclNode { pub span: Span, pub vis: String, // "pub" | "mod" pub name: String, pub extends: Option, pub members: Vec, // ServiceFnSig } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct ServiceFnSigNode { pub span: Span, pub name: String, pub params: Vec, pub ret: Box, // TypeName or TypeApp } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct ParamNode { pub span: Span, pub name: String, pub ty: Box, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct FnDeclNode { pub span: Span, pub name: String, pub params: Vec, pub ret: Option>, pub else_fallback: Option>, // Block pub body: Box, // Block } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct TypeDeclNode { pub span: Span, pub vis: Option, pub type_kind: String, // "struct" | "contract" | "error" pub name: String, pub is_host: bool, pub body: Box, // TypeBody } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct TypeBodyNode { pub span: Span, pub members: Vec, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct TypeMemberNode { pub span: Span, pub name: String, pub ty: Box, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct BlockNode { pub span: Span, pub stmts: Vec, pub tail: Option>, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct LetStmtNode { pub span: Span, pub name: String, pub is_mut: bool, pub ty: Option>, pub init: Box, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct ExprStmtNode { pub span: Span, pub expr: Box, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct ReturnStmtNode { pub span: Span, pub expr: Option>, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct IntLitNode { pub span: Span, pub value: i64, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct FloatLitNode { pub span: Span, pub value: f64, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct BoundedLitNode { pub span: Span, pub value: u32, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct StringLitNode { pub span: Span, pub value: String, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct IdentNode { pub span: Span, pub name: String, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct CallNode { pub span: Span, pub callee: Box, pub args: Vec, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct UnaryNode { pub span: Span, pub op: String, pub expr: Box, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct BinaryNode { pub span: Span, pub op: String, pub left: Box, pub right: Box, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct CastNode { pub span: Span, pub expr: Box, pub ty: Box, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct IfExprNode { pub span: Span, pub cond: Box, pub then_block: Box, pub else_block: Option>, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct WhenExprNode { pub span: Span, pub arms: Vec, // WhenArm } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct WhenArmNode { pub span: Span, pub cond: Box, pub body: Box, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct TypeNameNode { pub span: Span, pub name: String, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct TypeAppNode { pub span: Span, pub base: String, pub args: Vec, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct AllocNode { pub span: Span, pub ty: Box, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct MutateNode { pub span: Span, pub target: Box, pub binding: String, pub body: Box, // BlockNode } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct BorrowNode { pub span: Span, pub target: Box, pub binding: String, pub body: Box, // BlockNode } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct PeekNode { pub span: Span, pub target: Box, pub binding: String, pub body: Box, // BlockNode } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct MemberAccessNode { pub span: Span, pub object: Box, pub member: String, }