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 Partial,
34 Required,
37 New,
39}
40
41#[derive(Debug, Clone, PartialEq)]
43pub struct Attribute {
44 pub path: Vec<Name>,
45 pub args: Vec<super::Arg>,
46}
47
48#[derive(Debug, Clone, PartialEq)]
50pub struct Decl {
51 pub attributes: Vec<Attribute>,
52 pub doc: Vec<String>,
53 pub modifiers: Vec<Modifier>,
54 pub kind: DeclKind,
55 pub span: Span,
56}
57
58impl Decl {
59 pub fn has(&self, m: Modifier) -> bool {
60 self.modifiers.contains(&m)
61 }
62}
63
64#[derive(Debug, Clone, PartialEq, Default)]
67pub struct TypeHeader {
68 pub generics: Vec<Generic>,
69 pub ctor: Option<Vec<Param>>,
70 pub bases: Vec<Type>,
71 pub constraints: Vec<Where>,
72 pub has: Vec<Expr>,
73}
74
75#[derive(Debug, Clone, PartialEq)]
76pub enum DeclKind {
77 Using {
79 path: Vec<Name>,
80 global: bool,
81 statics: bool,
82 },
83 Namespace {
85 path: Vec<Name>,
86 body: Option<Vec<Decl>>,
87 },
88 Alias {
90 name: Name,
91 ty: Type,
92 },
93 Mod {
96 name: Name,
97 body: Vec<Decl>,
98 },
99 Event {
101 ty: Type,
102 name: Name,
103 },
104 Method(Method),
105 Delegate(Method),
108 Field(Field),
109 Property {
111 ty: Type,
112 name: Name,
113 accessors: Vec<Accessor>,
114 value: Option<Expr>,
115 explicit: Option<Type>,
118 },
119 Indexer(super::Indexer),
121 Operator(super::Operator),
123 Ctor(Ctor),
124 Type {
127 word: Name,
128 name: Name,
129 value: bool,
130 header: TypeHeader,
131 body: Vec<Decl>,
132 },
133 Enum {
135 name: Name,
136 generics: Vec<Generic>,
137 base: Option<Type>,
138 variants: Vec<Variant>,
139 body: Vec<Decl>,
140 },
141 Unit {
143 name: Name,
144 value: Option<Expr>,
145 },
146 Content {
149 kind: Name,
150 name: Name,
151 header: TypeHeader,
152 body: Vec<Decl>,
153 },
154 Component {
155 name: Name,
156 header: TypeHeader,
157 body: Vec<Decl>,
158 },
159 System {
161 name: Name,
162 params: Vec<Param>,
163 every: Option<Expr>,
164 body: Block,
165 },
166 Extend {
167 ty: Type,
168 header: TypeHeader,
169 body: Vec<Decl>,
170 },
171 Prop(Prop),
174 Screen {
175 name: Name,
176 header: TypeHeader,
177 ui: String,
178 body: Vec<Decl>,
179 },
180 Command {
181 name: String,
182 body: Vec<Decl>,
183 },
184 Test {
185 name: String,
186 body: Block,
187 },
188 Patch(Patch),
189 Targets(VersionCond),
191}
192
193#[derive(Debug, Clone, PartialEq)]
195pub struct Prop {
196 pub name: Name,
197 pub value: Expr,
198}
199
200#[derive(Debug, Clone, PartialEq)]
202pub struct Method {
203 pub ret: Option<Type>,
204 pub name: Name,
205 pub explicit: Option<Type>,
208 pub generics: Vec<Generic>,
209 pub params: Vec<Param>,
210 pub constraints: Vec<Where>,
211 pub requires: Option<Expr>,
212 pub body: Option<MethodBody>,
214}
215
216#[derive(Debug, Clone, PartialEq)]
217pub enum MethodBody {
218 Block(Block),
219 Expr(Expr),
220}
221
222#[derive(Debug, Clone, PartialEq)]
224pub struct Field {
225 pub ty: Type,
226 pub name: Name,
227 pub bound: Option<Expr>,
228 pub value: Option<Expr>,
229 pub was: Option<(Name, Option<Type>)>,
231}
232
233#[derive(Debug, Clone, PartialEq)]
235pub struct Accessor {
236 pub name: Name,
237 pub body: Option<MethodBody>,
238}
239
240#[derive(Debug, Clone, PartialEq)]
242pub struct Ctor {
243 pub name: Name,
244 pub params: Vec<Param>,
245 pub chain: Option<(Chain, Vec<super::Arg>)>,
247 pub body: Block,
248}
249
250#[derive(Debug, Clone, Copy, PartialEq, Eq)]
252pub enum Chain {
253 This,
254 Base,
255}
256
257#[derive(Debug, Clone, PartialEq)]
259pub struct Param {
260 pub extension: bool,
263 pub params: bool,
266 pub pass: Option<super::Pass>,
267 pub lifetime: Option<Name>,
269 pub ty: Type,
270 pub name: Name,
271 pub default: Option<Expr>,
272}
273
274#[derive(Debug, Clone, PartialEq)]
275pub struct Variant {
276 pub doc: Vec<String>,
278 pub name: Name,
279 pub fields: Vec<Param>,
280 pub value: Option<Expr>,
282}
283
284#[derive(Debug, Clone, PartialEq)]
286pub enum VersionCond {
287 Compare { op: super::BinOp, version: String },
288 Range { from: String, to: String },
289}