fkl-parser 0.4.0

Feakin is a architecture design and visual collaboration tool. This is the parser for Feakin.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
use std::collections::HashMap;
use pest::Span;

// Todo: add Loc support
#[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Hash, Clone, Copy, Default)]
pub struct Loc(pub usize, pub usize);

impl Loc {
  pub(crate) fn from_pair(range: Span) -> Loc {
    Loc(range.start(), range.end())
  }
}

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct Identifier {
  pub name: String,
  pub loc: Loc,
}

// strategy DDD

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FklDeclaration {
  None,
  Include(IncludeDecl),
  ContextMap(ContextMapDecl),
  BoundedContext(BoundedContextDecl),
  Aggregate(AggregateDecl),
  Entity(EntityDecl),
  ValueObject(ValueObjectDecl),
  Implementation(ImplementationDecl),
  Struct(StructDecl),
  // Domain(DomainDecl),
  Component(ComponentDecl),
  Layered(LayeredDecl),
  SourceSets(SourceSetsDecl),
  Env(EnvDecl),
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IncludeDecl {
  pub path: String,
  pub loc: Loc,
}

// todo: add Loc support
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UbiquitousLanguage {
  pub name: String,
  pub description: String,
  pub words: HashMap<String, UniqueWord>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UniqueWord {
  pub unique_name: String,
  pub display_name: String,
  pub context_name: Option<String>,
}

// #[derive(Debug, Clone, PartialEq, Eq)]
// pub struct DomainDecl {
//   pub name: String,
//   pub description: String,
//   pub sub_domains: Vec<SubDomain>,
// }
//
// #[derive(Debug, Clone, PartialEq, Eq)]
// pub struct SubDomain {
//   pub name: String,
//   pub subdomain_type: String,
//   pub entities: Vec<BoundedContextDecl>,
// }

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct ContextMapDecl {
  pub name: Identifier,
  pub contexts: Vec<BoundedContextDecl>,
  pub relations: Vec<ContextRelation>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct BoundedContextDecl {
  pub name: String,
  pub domain_events: Vec<DomainEventDecl>,
  pub aggregates: Vec<AggregateDecl>,
  pub used_domain_objects: Vec<UsedDomainObject>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct DomainEventDecl {
  pub name: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct UsedImplementation {
  pub name: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct ContextRelation {
  pub source: String,
  pub target: String,
  pub direction: RelationDirection,
  pub source_types: Vec<String>,
  pub target_types: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RelationDirection {
  Undirected,
  // -->
  PositiveDirected,
  // <--
  NegativeDirected,
  // <->
  BiDirected,
}

impl Default for RelationDirection {
  fn default() -> Self {
    RelationDirection::Undirected
  }
}

// tactic DDD

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DomainServiceDecl {
  pub name: String,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ApplicationServiceDecl {
  pub name: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct AggregateDecl {
  pub name: String,
  pub inline_doc: String,
  pub used_domain_objects: Vec<UsedDomainObject>,
  pub entities: Vec<EntityDecl>,
  pub value_objects: Vec<ValueObjectDecl>,
  pub domain_events: Vec<DomainEventDecl>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct StructDecl {
  pub name: String,
  pub inline_doc: String,
  pub fields: Vec<VariableDefinition>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct UsedDomainObject {
  pub name: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct EntityDecl {
  pub name: String,
  pub is_aggregate_root: bool,
  pub identify: VariableDefinition,
  pub inline_doc: String,
  pub fields: Vec<VariableDefinition>,
  pub value_objects: Vec<ValueObjectDecl>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct VariableDefinition {
  pub name: String,
  pub type_type: String,
  pub initializer: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct AttributeDefinition {
  pub key: String,
  pub value: Vec<String>,
}

// ???
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Property {
  pub required: bool,
  pub nullable: bool,
  pub unique: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct ValueObjectDecl {
  pub name: String,
  pub inline_doc: String,
  pub fields: Vec<VariableDefinition>,
}

// Implementation Block

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct ImplementationDecl {
  pub name: String,
  pub inline_doc: String,
  pub qualified_name: String,
  // can be file path or url
  pub endpoint: EndpointDecl,
  pub target: Option<ImplementationTarget>,
  pub flow: Option<FlowDecl>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct ImplementationTarget {
  pub target_type: ImplementationTargetType,
  pub name: String,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ImplementationTargetType {
  None,
  Aggregate,
  Entity,
  ValueObject,
}

impl Default for ImplementationTargetType {
  fn default() -> Self {
    ImplementationTargetType::None
  }
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct SourceSetsDecl {
  pub name: String,
  pub source_sets: Vec<SourceSetDecl>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct SourceSetDecl {
  pub name: String,
  pub attributes: Vec<AttributeDefinition>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct EndpointDecl {
  pub name: String,
  pub method: String,
  pub uri: String,
  pub authorization: Option<AuthorizationDecl>,
  pub request: Option<HttpRequestDecl>,
  pub response: Option<HttpResponseDecl>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct AuthorizationDecl {
  pub auth_type: String,
  pub username: Option<String>,
  pub password: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct HttpRequestDecl {
  pub name: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct HttpResponseDecl {
  pub name: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct FlowDecl {
  pub inline_doc: String,
  pub steps: Vec<StepDecl>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StepDecl {
  MethodCall(MethodCallDecl),
  Message(MessageDecl),
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct MethodCallDecl {
  pub name: String,
  pub object: String,
  pub method: String,
  pub arguments: Vec<VariableDefinition>,
  pub return_type: Option<VariableDefinition>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct MessageDecl {
  pub from: String,
  pub topic: String,
  pub message: String,
}

// Binding block

/// [`SourceSet`] is a code block is a block of code that can be executed.
/// It can be a function, a method, a class, a trait, a module, a file, a package, a library, a program, etc.
/// - [`source_type`]: the type of the source code, e.g. feakin, java, puml/uml, swagger, etc.
/// - [`src_dir`]: the directory of the source code
/// - [`filter`]: the filter of the source code
///
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct SourceSet {
  pub name: String,
  /// default to be Feakin?
  pub source_type: String,
  pub src_dirs: Vec<String>,
  pub filter: String,
}

// Layered Block

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct LayeredDecl {
  pub name: String,
  pub inline_doc: String,
  pub dependencies: Vec<LayerRelationDecl>,
  pub layers: Vec<LayerDecl>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct LayerRelationDecl {
  pub source: String,
  pub target: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct LayerDecl {
  pub name: String,
  pub inline_doc: String,
  pub package: String,
}

// Architecture Binding Block

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Trait {
  pub name: String,
  pub methods: Vec<Function>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Function {
  pub name: String,
  pub description: String,
  pub parameters: Vec<Parameter>,
  pub return_type: Vec<Parameter>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Parameter {
  pub name: String,
  pub param_type: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct ComponentDecl {
  pub name: String,
  pub component_type: ComponentType,
  pub inline_doc: String,
  pub used_domain_objects: Vec<UsedDomainObject>,
  pub attributes: Vec<AttributeDefinition>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ComponentType {
  Application,
  Service,
  Module,
  Package,
  //  or Classes ?
  Entities,
}

impl Default for ComponentType {
  fn default() -> Self {
    ComponentType::Application
  }
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct EnvDecl {
  pub name: String,
  pub inline_doc: String,
  pub datasource: Option<DatasourceDecl>,
  pub message_broker: Option<MessageBrokerDecl>,
  pub server: Option<ServerDecl>,
  pub customs: Vec<CustomDecl>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct DatasourceDecl {
  pub url: String,
  pub host: String,
  pub port: String,
  pub driver: String,
  pub username: String,
  pub password: String,
  pub database: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct MessageBrokerDecl {
  pub name: String,
  pub inline_doc: String,
  pub attributes: Vec<AttributeDefinition>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct ServerDecl {
  pub port: u16,
  pub attributes: Vec<AttributeDefinition>,
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct CustomDecl {
  pub name: String,
  pub inline_doc: String,
  pub attributes: Vec<AttributeDefinition>,
}