mod expr;
mod patch;
pub use expr::{
Arg, Arm, BinOp, Block, Cond, Expr, ExprKind, Pattern, Stmt, StrSeg, Type, TypeKind, UnOp,
};
pub use patch::{Callee, Local, Method, Patch, PatchItem, Point, Selector};
use crate::source::token::Span;
#[derive(Debug, Clone, PartialEq)]
pub struct Name {
pub text: String,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct File {
pub decls: Vec<Decl>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Modifier {
Server,
Client,
Shared,
Saved,
Synced,
Tune,
Pub,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Decl {
pub doc: Vec<String>,
pub modifiers: Vec<Modifier>,
pub kind: DeclKind,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DeclKind {
Use {
path: Vec<Name>,
items: Vec<Name>,
alias: Option<Name>,
},
Mod {
name: Name,
props: Vec<Prop>,
},
Fn(FnDecl),
Let {
pattern: Pattern,
ty: Option<Type>,
value: Expr,
},
Var(VarDecl),
Const {
name: Name,
ty: Option<Type>,
value: Expr,
},
Val {
name: Name,
ty: Option<Type>,
value: Expr,
},
Unit {
name: Name,
value: Option<Expr>,
},
Type {
name: Name,
generics: Vec<Generic>,
ty: Type,
},
Record {
name: Name,
generics: Vec<Generic>,
fields: Vec<Param>,
body: Vec<Decl>,
},
Union {
name: Name,
generics: Vec<Generic>,
variants: Vec<Variant>,
body: Vec<Decl>,
},
Enum {
name: Name,
cases: Vec<Name>,
body: Vec<Decl>,
},
Extend {
ty: Type,
adds: Option<Type>,
body: Vec<Decl>,
},
Content {
kind: Name,
name: Name,
base: Option<Type>,
body: Vec<Decl>,
},
Recipe {
result: Type,
kind: Name,
rows: Vec<String>,
keys: Vec<Prop>,
},
Prop(Prop),
Slots {
name: Name,
size: Expr,
of: Option<Type>,
},
State {
scope: Name,
body: Vec<Decl>,
},
Screen {
name: Name,
params: Vec<Param>,
ui: String,
body: Vec<Decl>,
},
Action(FnDecl),
Command {
name: String,
body: Vec<Decl>,
},
On {
event: Vec<Name>,
params: Vec<Name>,
body: Block,
},
Test {
name: String,
body: Block,
},
Version {
cond: VersionCond,
then: Vec<Decl>,
otherwise: Option<Vec<Decl>>,
},
Native {
library: String,
fns: Vec<FnDecl>,
},
Patch(Patch),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Prop {
pub name: Name,
pub value: Expr,
pub computed: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FnDecl {
pub name: Name,
pub generics: Vec<Generic>,
pub params: Vec<Param>,
pub ret: Option<Type>,
pub requires: Option<Expr>,
pub body: Option<FnBody>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum FnBody {
Block(Block),
Expr(Expr),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Param {
pub var: bool,
pub name: Name,
pub ty: Option<Type>,
pub default: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct VarDecl {
pub name: Name,
pub ty: Option<Type>,
pub value: Option<Expr>,
pub was: Option<(Name, Option<Type>)>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Generic {
pub name: Name,
pub bound: Option<Type>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Variant {
pub name: Name,
pub fields: Vec<Param>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum VersionCond {
Compare { op: BinOp, version: String },
Range { from: String, to: String },
}