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 Indexer(super::Indexer),
108 Ctor(Ctor),
109 Type {
112 word: Name,
113 name: Name,
114 value: bool,
115 header: TypeHeader,
116 body: Vec<Decl>,
117 },
118 Enum {
120 name: Name,
121 generics: Vec<Generic>,
122 base: Option<Type>,
123 variants: Vec<Variant>,
124 body: Vec<Decl>,
125 },
126 Unit {
128 name: Name,
129 value: Option<Expr>,
130 },
131 Content {
134 kind: Name,
135 name: Name,
136 header: TypeHeader,
137 body: Vec<Decl>,
138 },
139 Component {
140 name: Name,
141 header: TypeHeader,
142 body: Vec<Decl>,
143 },
144 System {
146 name: Name,
147 params: Vec<Param>,
148 every: Option<Expr>,
149 body: Block,
150 },
151 Extend {
152 ty: Type,
153 header: TypeHeader,
154 body: Vec<Decl>,
155 },
156 Prop(Prop),
158 Screen {
159 name: Name,
160 header: TypeHeader,
161 ui: String,
162 body: Vec<Decl>,
163 },
164 Command {
165 name: String,
166 body: Vec<Decl>,
167 },
168 Test {
169 name: String,
170 body: Block,
171 },
172 Patch(Patch),
173 Targets(VersionCond),
175}
176
177#[derive(Debug, Clone, PartialEq)]
179pub struct Prop {
180 pub name: Name,
181 pub value: Expr,
182}
183
184#[derive(Debug, Clone, PartialEq)]
186pub struct Method {
187 pub ret: Option<Type>,
188 pub name: Name,
189 pub generics: Vec<Generic>,
190 pub params: Vec<Param>,
191 pub constraints: Vec<Where>,
192 pub requires: Option<Expr>,
193 pub body: Option<MethodBody>,
195}
196
197#[derive(Debug, Clone, PartialEq)]
198pub enum MethodBody {
199 Block(Block),
200 Expr(Expr),
201}
202
203#[derive(Debug, Clone, PartialEq)]
205pub struct Field {
206 pub ty: Type,
207 pub name: Name,
208 pub bound: Option<Expr>,
209 pub value: Option<Expr>,
210 pub was: Option<(Name, Option<Type>)>,
212}
213
214#[derive(Debug, Clone, PartialEq)]
216pub struct Accessor {
217 pub name: Name,
218 pub body: Option<MethodBody>,
219}
220
221#[derive(Debug, Clone, PartialEq)]
223pub struct Ctor {
224 pub name: Name,
225 pub params: Vec<Param>,
226 pub chain: Option<(Chain, Vec<super::Arg>)>,
228 pub body: Block,
229}
230
231#[derive(Debug, Clone, Copy, PartialEq, Eq)]
233pub enum Chain {
234 This,
235 Base,
236}
237
238#[derive(Debug, Clone, PartialEq)]
240pub struct Param {
241 pub pass: Option<super::Pass>,
242 pub lifetime: Option<Name>,
244 pub ty: Type,
245 pub name: Name,
246 pub default: Option<Expr>,
247}
248
249#[derive(Debug, Clone, PartialEq)]
250pub struct Variant {
251 pub name: Name,
252 pub fields: Vec<Param>,
253 pub value: Option<Expr>,
255}
256
257#[derive(Debug, Clone, PartialEq)]
259pub enum VersionCond {
260 Compare { op: super::BinOp, version: String },
261 Range { from: String, to: String },
262}