use super::{Block, Expr, Generic, Name, Patch, Type, Where};
use crate::source::token::Span;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Modifier {
Public,
Private,
Internal,
Static,
Const,
Readonly,
Async,
Server,
Client,
Shared,
Saved,
Synced,
Tune,
Protected,
Abstract,
Virtual,
Override,
Sealed,
Ref,
Extern,
Partial,
Required,
New,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Attribute {
pub path: Vec<Name>,
pub args: Vec<super::Arg>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Decl {
pub attributes: Vec<Attribute>,
pub doc: Vec<String>,
pub modifiers: Vec<Modifier>,
pub kind: DeclKind,
pub span: Span,
}
impl Decl {
pub fn has(&self, m: Modifier) -> bool {
self.modifiers.contains(&m)
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct TypeHeader {
pub generics: Vec<Generic>,
pub ctor: Option<Vec<Param>>,
pub bases: Vec<Type>,
pub constraints: Vec<Where>,
pub has: Vec<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DeclKind {
Using {
path: Vec<Name>,
global: bool,
statics: bool,
},
Namespace {
path: Vec<Name>,
body: Option<Vec<Decl>>,
},
Alias {
name: Name,
ty: Type,
},
Mod {
name: Name,
body: Vec<Decl>,
},
Event {
ty: Type,
name: Name,
},
Method(Method),
Delegate(Method),
Field(Field),
Property {
ty: Type,
name: Name,
accessors: Vec<Accessor>,
value: Option<Expr>,
explicit: Option<Type>,
},
Indexer(super::Indexer),
Operator(super::Operator),
Ctor(Ctor),
Type {
word: Name,
name: Name,
value: bool,
header: TypeHeader,
body: Vec<Decl>,
},
Enum {
name: Name,
generics: Vec<Generic>,
base: Option<Type>,
variants: Vec<Variant>,
body: Vec<Decl>,
},
Unit {
name: Name,
value: Option<Expr>,
},
Content {
kind: Name,
name: Name,
header: TypeHeader,
body: Vec<Decl>,
},
Component {
name: Name,
header: TypeHeader,
body: Vec<Decl>,
},
System {
name: Name,
params: Vec<Param>,
every: Option<Expr>,
body: Block,
},
Extend {
ty: Type,
header: TypeHeader,
body: Vec<Decl>,
},
Prop(Prop),
Screen {
name: Name,
header: TypeHeader,
ui: String,
body: Vec<Decl>,
},
Command {
name: String,
body: Vec<Decl>,
},
Test {
name: String,
body: Block,
},
Patch(Patch),
Targets(VersionCond),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Prop {
pub name: Name,
pub value: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Method {
pub ret: Option<Type>,
pub name: Name,
pub explicit: Option<Type>,
pub generics: Vec<Generic>,
pub params: Vec<Param>,
pub constraints: Vec<Where>,
pub requires: Option<Expr>,
pub body: Option<MethodBody>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum MethodBody {
Block(Block),
Expr(Expr),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Field {
pub ty: Type,
pub name: Name,
pub bound: Option<Expr>,
pub value: Option<Expr>,
pub was: Option<(Name, Option<Type>)>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Accessor {
pub name: Name,
pub body: Option<MethodBody>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Ctor {
pub name: Name,
pub params: Vec<Param>,
pub chain: Option<(Chain, Vec<super::Arg>)>,
pub body: Block,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Chain {
This,
Base,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Param {
pub extension: bool,
pub params: bool,
pub pass: Option<super::Pass>,
pub lifetime: Option<Name>,
pub ty: Type,
pub name: Name,
pub default: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Variant {
pub doc: Vec<String>,
pub name: Name,
pub fields: Vec<Param>,
pub value: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum VersionCond {
Compare { op: super::BinOp, version: String },
Range { from: String, to: String },
}