use serde::Serialize; #[derive(Debug, Clone, Serialize)] pub struct FieldList(pub Vec<(String, bool, TypeExpr)>); #[derive(Debug, Clone, Serialize)] pub struct ParamList(pub Vec); #[derive(Debug, Clone, Serialize)] pub struct Block(pub Vec); #[derive(Debug, Clone, Serialize)] pub enum TypePostfix { Ref, RefMut, } #[derive(Debug, Clone, Serialize)] pub enum Visibility { Public, Private, } #[derive(Debug, Clone, Serialize)] pub enum Attribute { /// #[test] Path(Path), /// #[name = "value"] NameValue { path: Path, value: Literal }, /// #[derive(Clone, Copy)] List { path: Path, items: Vec }, } #[derive(Debug, Clone, Serialize)] pub enum TypeExprKind { Path(Path), PathParams(Path, Vec), Tuple(Vec), } #[derive(Debug, Clone, Serialize)] pub struct TypeExpr(pub TypeExprKind, pub Vec); #[derive(Debug, Clone, Serialize)] pub struct Path(pub Vec); #[derive(Debug, Clone, Serialize)] pub enum BinaryOp { Plus, Minus, Multiply, Divide, Modulo, Equal, NotEqual, LessThan, GreaterThan, LessThanOrEqual, GreaterThanOrEqual, } #[derive(Debug, Clone, Serialize)] pub struct TopLevel(pub TopLevelKind, pub Vec); #[derive(Debug, Clone, Serialize)] pub enum TopLevelKind { ModAttribute, Include(Path), StructDecl { export: bool, name: String, fields: FieldList, }, FunctionDecl(FunctionDecl), ClassDecl { export: bool, name: String, fields: Vec, constructor: ClassConstructor, methods: Vec, }, } #[derive(Debug, Clone, Serialize)] pub struct ClassConstructor { pub export: bool, pub params: ParamList, pub body: Block, } #[derive(Debug, Clone, Serialize)] pub struct FunctionDecl { pub export: bool, pub name: String, pub params: ParamList, pub return_type: TypeExpr, pub body: Block, } #[derive(Debug, Clone, Serialize)] pub enum Postfix { FieldAccess(String), Call(Vec), MacroCall(String), StructCall(Vec<(String, Expression)>), Index(Expression), Binary(BinaryOp, Expression), } #[derive(Debug, Clone, Serialize)] pub enum Prefix { Ref, RefMut, Deref, New, } #[derive(Debug, Clone, Serialize)] pub enum Statement { Expression(Expression), Block(Block), VarDecl(VarDeclStmt), VarAssign(VarAssignStmt), If { initial: StatementBranch, else_if: Vec, else_branch: Option>, }, While(StatementBranch), CStyleFor { init: Box, condition: Expression, update: Box, body: Box, }, For { pattern: String, iterator: Expression, body: Box, }, Return(Option), Break, Continue, } #[derive(Debug, Clone, Serialize)] pub struct VarDecl { pub mutable: bool, pub name: String, pub type_: Option, } #[derive(Debug, Clone, Serialize)] pub struct VarDeclStmt { pub decl: VarDecl, pub init: Option, } #[derive(Debug, Clone, Serialize)] pub struct VarAssignStmt { pub target: Expression, pub value: Expression, } #[derive(Debug, Clone, Serialize)] pub struct StatementBranch { pub condition: Expression, pub body: Box, } #[derive(Debug, Clone, Serialize)] pub enum Expression { Literal(Literal), Path(Path), Fix { initial: Box, prefixes: Vec, postfixes: Vec, }, } #[derive(Debug, Clone, Serialize)] pub enum Literal { String(String), Int(i64), Float(f64), Bool(bool), Tuple(Vec), }