1use super::{Block, Expr, Generic, Name, Patch, Type, Where};
5use crate::source::token::Span;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum Modifier {
10 Public,
11 Private,
12 Internal,
13 Static,
14 Const,
15 Readonly,
16 Async,
17 Server,
18 Client,
19 Shared,
20 Saved,
21 Synced,
22 Tune,
23 Protected,
24 Abstract,
25 Virtual,
26 Override,
27 Sealed,
28 Ref,
30 Extern,
32}
33
34#[derive(Debug, Clone, PartialEq)]
36pub struct Attribute {
37 pub path: Vec<Name>,
38 pub args: Vec<super::Arg>,
39}
40
41#[derive(Debug, Clone, PartialEq)]
43pub struct Decl {
44 pub attributes: Vec<Attribute>,
45 pub doc: Vec<String>,
46 pub modifiers: Vec<Modifier>,
47 pub kind: DeclKind,
48 pub span: Span,
49}
50
51impl Decl {
52 pub fn has(&self, m: Modifier) -> bool {
53 self.modifiers.contains(&m)
54 }
55}
56
57#[derive(Debug, Clone, PartialEq, Default)]
60pub struct TypeHeader {
61 pub generics: Vec<Generic>,
62 pub ctor: Option<Vec<Param>>,
63 pub bases: Vec<Type>,
64 pub constraints: Vec<Where>,
65 pub has: Vec<Expr>,
66}
67
68#[derive(Debug, Clone, PartialEq)]
69pub enum DeclKind {
70 Using {
72 path: Vec<Name>,
73 global: bool,
74 statics: bool,
75 },
76 Namespace {
78 path: Vec<Name>,
79 body: Option<Vec<Decl>>,
80 },
81 Alias {
83 name: Name,
84 ty: Type,
85 },
86 Mod {
89 name: Name,
90 body: Vec<Decl>,
91 },
92 Event {
94 ty: Type,
95 name: Name,
96 },
97 Method(Method),
98 Field(Field),
99 Property {
101 ty: Type,
102 name: Name,
103 accessors: Vec<Accessor>,
104 value: Option<Expr>,
105 },
106 Ctor(Ctor),
107 Type {
110 word: Name,
111 name: Name,
112 value: bool,
113 header: TypeHeader,
114 body: Vec<Decl>,
115 },
116 Enum {
118 name: Name,
119 generics: Vec<Generic>,
120 base: Option<Type>,
121 variants: Vec<Variant>,
122 body: Vec<Decl>,
123 },
124 Unit {
126 name: Name,
127 value: Option<Expr>,
128 },
129 Content {
132 kind: Name,
133 name: Name,
134 header: TypeHeader,
135 body: Vec<Decl>,
136 },
137 Component {
138 name: Name,
139 header: TypeHeader,
140 body: Vec<Decl>,
141 },
142 System {
144 name: Name,
145 params: Vec<Param>,
146 every: Option<Expr>,
147 body: Block,
148 },
149 Extend {
150 ty: Type,
151 header: TypeHeader,
152 body: Vec<Decl>,
153 },
154 Prop(Prop),
156 Screen {
157 name: Name,
158 header: TypeHeader,
159 ui: String,
160 body: Vec<Decl>,
161 },
162 Command {
163 name: String,
164 body: Vec<Decl>,
165 },
166 Test {
167 name: String,
168 body: Block,
169 },
170 Patch(Patch),
171 Targets(VersionCond),
173}
174
175#[derive(Debug, Clone, PartialEq)]
177pub struct Prop {
178 pub name: Name,
179 pub value: Expr,
180}
181
182#[derive(Debug, Clone, PartialEq)]
184pub struct Method {
185 pub ret: Option<Type>,
186 pub name: Name,
187 pub generics: Vec<Generic>,
188 pub params: Vec<Param>,
189 pub constraints: Vec<Where>,
190 pub requires: Option<Expr>,
191 pub body: Option<MethodBody>,
193}
194
195#[derive(Debug, Clone, PartialEq)]
196pub enum MethodBody {
197 Block(Block),
198 Expr(Expr),
199}
200
201#[derive(Debug, Clone, PartialEq)]
203pub struct Field {
204 pub ty: Type,
205 pub name: Name,
206 pub bound: Option<Expr>,
207 pub value: Option<Expr>,
208 pub was: Option<(Name, Option<Type>)>,
210}
211
212#[derive(Debug, Clone, PartialEq)]
214pub struct Accessor {
215 pub name: Name,
216 pub body: Option<MethodBody>,
217}
218
219#[derive(Debug, Clone, PartialEq)]
221pub struct Ctor {
222 pub name: Name,
223 pub params: Vec<Param>,
224 pub chain: Option<(Chain, Vec<super::Arg>)>,
226 pub body: Block,
227}
228
229#[derive(Debug, Clone, Copy, PartialEq, Eq)]
231pub enum Chain {
232 This,
233 Base,
234}
235
236#[derive(Debug, Clone, PartialEq)]
238pub struct Param {
239 pub pass: Option<super::Pass>,
240 pub lifetime: Option<Name>,
242 pub ty: Type,
243 pub name: Name,
244 pub default: Option<Expr>,
245}
246
247#[derive(Debug, Clone, PartialEq)]
248pub struct Variant {
249 pub name: Name,
250 pub fields: Vec<Param>,
251 pub value: Option<Expr>,
253}
254
255#[derive(Debug, Clone, PartialEq)]
257pub enum VersionCond {
258 Compare { op: super::BinOp, version: String },
259 Range { from: String, to: String },
260}