phenotyper 0.3.0

Core compiler library for the Phenotyper structural artifact definition language
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
/// This file is maintained by rustemo but can be modified manually.
/// All manual changes will be preserved except non-doc comments.
use rustemo::Token as RustemoToken;
use super::phenotyper::{TokenKind, Context};
pub type Input = str;
pub type Ctx<'i> = Context<'i, Input>;
#[allow(dead_code)]
pub type Token<'i> = RustemoToken<'i, Input, TokenKind>;
pub type Ident = String;
pub fn ident(_ctx: &Ctx, token: Token) -> Ident {
    token.value.into()
}
pub type StringLiteral = String;
pub fn string_literal(_ctx: &Ctx, token: Token) -> StringLiteral {
    token.value.into()
}
#[derive(Debug, Clone)]
pub struct File {
    pub ns: NamespaceScope,
}
pub fn file_c1(_ctx: &Ctx, ns: NamespaceScope) -> File {
    File { ns }
}
#[derive(Debug, Clone)]
pub struct NamespaceScope {
    pub path: NamespacePath,
    pub uses: UsesDecl0,
    pub decls: TopLevelDecl0,
}
pub fn namespace_scope_c1(
    _ctx: &Ctx,
    path: NamespacePath,
    uses: UsesDecl0,
    decls: TopLevelDecl0,
) -> NamespaceScope {
    NamespaceScope {
        path,
        uses,
        decls,
    }
}
pub type UsesDecl1 = Vec<UsesDecl>;
pub fn uses_decl1_c1(
    _ctx: &Ctx,
    mut uses_decl1: UsesDecl1,
    uses_decl: UsesDecl,
) -> UsesDecl1 {
    uses_decl1.push(uses_decl);
    uses_decl1
}
pub fn uses_decl1_uses_decl(_ctx: &Ctx, uses_decl: UsesDecl) -> UsesDecl1 {
    vec![uses_decl]
}
pub type UsesDecl0 = Option<UsesDecl1>;
pub fn uses_decl0_uses_decl1(_ctx: &Ctx, uses_decl1: UsesDecl1) -> UsesDecl0 {
    Some(uses_decl1)
}
pub fn uses_decl0_empty(_ctx: &Ctx) -> UsesDecl0 {
    None
}
pub type TopLevelDecl1 = Vec<TopLevelDecl>;
pub fn top_level_decl1_c1(
    _ctx: &Ctx,
    mut top_level_decl1: TopLevelDecl1,
    top_level_decl: TopLevelDecl,
) -> TopLevelDecl1 {
    top_level_decl1.push(top_level_decl);
    top_level_decl1
}
pub fn top_level_decl1_top_level_decl(
    _ctx: &Ctx,
    top_level_decl: TopLevelDecl,
) -> TopLevelDecl1 {
    vec![top_level_decl]
}
pub type TopLevelDecl0 = Option<TopLevelDecl1>;
pub fn top_level_decl0_top_level_decl1(
    _ctx: &Ctx,
    top_level_decl1: TopLevelDecl1,
) -> TopLevelDecl0 {
    Some(top_level_decl1)
}
pub fn top_level_decl0_empty(_ctx: &Ctx) -> TopLevelDecl0 {
    None
}
pub type NamespacePath = Ident1;
pub fn namespace_path_ident1(_ctx: &Ctx, ident1: Ident1) -> NamespacePath {
    ident1
}
pub type Ident1 = Vec<Ident>;
pub fn ident1_c1(_ctx: &Ctx, mut ident1: Ident1, ident: Ident) -> Ident1 {
    ident1.push(ident);
    ident1
}
pub fn ident1_ident(_ctx: &Ctx, ident: Ident) -> Ident1 {
    vec![ident]
}
#[derive(Debug, Clone)]
pub struct UsesDecl {
    pub path: NamespacePath,
}
pub fn uses_decl_c1(_ctx: &Ctx, path: NamespacePath) -> UsesDecl {
    UsesDecl { path }
}
#[derive(Debug, Clone)]
pub enum TopLevelDecl {
    TypeDecl(TypeDecl),
    TypeDef(TypeDef),
}
pub fn top_level_decl_type_decl(_ctx: &Ctx, type_decl: TypeDecl) -> TopLevelDecl {
    TopLevelDecl::TypeDecl(type_decl)
}
pub fn top_level_decl_type_def(_ctx: &Ctx, type_def: TypeDef) -> TopLevelDecl {
    TopLevelDecl::TypeDef(type_def)
}
#[derive(Debug, Clone)]
pub struct TypeDecl {
    pub name: Ident,
    pub body: TypeDeclBody,
}
pub fn type_decl_c1(_ctx: &Ctx, name: Ident, body: TypeDeclBody) -> TypeDecl {
    TypeDecl { name, body }
}
#[derive(Debug, Clone)]
pub struct Alias {
    pub alias: TypeExpr,
}
#[derive(Debug, Clone)]
pub struct Enum {
    pub members: EnumMembers,
}
#[derive(Debug, Clone)]
pub enum TypeDeclBody {
    Alias(Alias),
    Enum(Enum),
}
pub fn type_decl_body_alias(_ctx: &Ctx, alias: TypeExpr) -> TypeDeclBody {
    TypeDeclBody::Alias(Alias { alias })
}
pub fn type_decl_body_enum(_ctx: &Ctx, members: EnumMembers) -> TypeDeclBody {
    TypeDeclBody::Enum(Enum { members })
}
#[derive(Debug, Clone)]
pub struct Cons {
    pub first: Ident,
    pub rest: Box<EnumMembers>,
}
#[derive(Debug, Clone)]
pub struct Single {
    pub last: Ident,
}
#[derive(Debug, Clone)]
pub enum EnumMembers {
    Cons(Cons),
    Single(Single),
}
pub fn enum_members_cons(_ctx: &Ctx, first: Ident, rest: EnumMembers) -> EnumMembers {
    EnumMembers::Cons(Cons {
        first,
        rest: Box::new(rest),
    })
}
pub fn enum_members_single(_ctx: &Ctx, last: Ident) -> EnumMembers {
    EnumMembers::Single(Single { last })
}
#[derive(Debug, Clone)]
pub struct TypeDef {
    pub name: Ident,
    pub plural_clause: PluralClauseOpt,
    pub items: BodyItem1,
}
pub fn type_def_c1(
    _ctx: &Ctx,
    name: Ident,
    plural_clause: PluralClauseOpt,
    items: BodyItem1,
) -> TypeDef {
    TypeDef {
        name,
        plural_clause,
        items,
    }
}
pub type PluralClauseOpt = Option<PluralClause>;
pub fn plural_clause_opt_plural_clause(
    _ctx: &Ctx,
    plural_clause: PluralClause,
) -> PluralClauseOpt {
    Some(plural_clause)
}
pub fn plural_clause_opt_empty(_ctx: &Ctx) -> PluralClauseOpt {
    None
}
pub type BodyItem1 = Vec<BodyItem>;
pub fn body_item1_c1(
    _ctx: &Ctx,
    mut body_item1: BodyItem1,
    body_item: BodyItem,
) -> BodyItem1 {
    body_item1.push(body_item);
    body_item1
}
pub fn body_item1_body_item(_ctx: &Ctx, body_item: BodyItem) -> BodyItem1 {
    vec![body_item]
}
#[derive(Debug, Clone)]
pub struct PluralClause {
    pub plural_name: Ident,
}
pub fn plural_clause_c1(_ctx: &Ctx, plural_name: Ident) -> PluralClause {
    PluralClause { plural_name }
}
#[derive(Debug, Clone)]
pub struct Field {
    pub field: FieldDecl,
}
#[derive(Debug, Clone)]
pub struct Render {
    pub render: RenderExpr,
}
#[derive(Debug, Clone)]
pub struct NestedType {
    pub nested: TypeDef,
}
#[derive(Debug, Clone)]
pub enum BodyItem {
    Field(Field),
    Render(Render),
    NestedTypePlural(NestedType),
    NestedType(NestedType),
}
pub fn body_item_nested_type_plural(
    _ctx: &Ctx,
    name: Ident,
    plural_clause: PluralClause,
    items: BodyItem1,
) -> BodyItem {
    BodyItem::NestedTypePlural(NestedType {
        nested: TypeDef {
            name,
            plural_clause: Some(plural_clause),
            items,
        },
    })
}
pub fn body_item_nested_type(_ctx: &Ctx, name: Ident, items: BodyItem1) -> BodyItem {
    BodyItem::NestedType(NestedType {
        nested: TypeDef {
            name,
            plural_clause: None,
            items,
        },
    })
}
pub fn body_item_field(
    _ctx: &Ctx,
    name: Ident,
    req: Requiredness,
    type_expr: TypeExpr,
) -> BodyItem {
    BodyItem::Field(Field {
        field: FieldDecl { name, req, type_expr },
    })
}
pub fn body_item_render(_ctx: &Ctx, render: RenderExpr) -> BodyItem {
    BodyItem::Render(Render { render })
}
#[derive(Debug, Clone)]
pub struct FieldDecl {
    pub name: Ident,
    pub req: Requiredness,
    pub type_expr: TypeExpr,
}
pub fn field_decl_c1(
    _ctx: &Ctx,
    name: Ident,
    req: Requiredness,
    type_expr: TypeExpr,
) -> FieldDecl {
    FieldDecl { name, req, type_expr }
}
#[derive(Debug, Clone)]
pub enum Requiredness {
    Req,
    Opt,
}
pub fn requiredness_req(_ctx: &Ctx) -> Requiredness {
    Requiredness::Req
}
pub fn requiredness_opt(_ctx: &Ctx) -> Requiredness {
    Requiredness::Opt
}
#[derive(Debug, Clone)]
pub struct Cardinalized {
    pub base: TypeName,
    pub card: CardinalityOp,
}
#[derive(Debug, Clone)]
pub struct Union {
    pub members: TypeName1,
}
#[derive(Debug, Clone)]
pub struct Simple {
    pub name: TypeName,
}
#[derive(Debug, Clone)]
pub enum TypeExpr {
    Cardinalized(Cardinalized),
    Union(Union),
    Simple(Simple),
}
pub fn type_expr_cardinalized(
    _ctx: &Ctx,
    base: TypeName,
    card: CardinalityOp,
) -> TypeExpr {
    TypeExpr::Cardinalized(Cardinalized { base, card })
}
pub fn type_expr_union(_ctx: &Ctx, members: TypeName1) -> TypeExpr {
    TypeExpr::Union(Union { members })
}
pub fn type_expr_simple(_ctx: &Ctx, name: TypeName) -> TypeExpr {
    TypeExpr::Simple(Simple { name })
}
pub type TypeName1 = Vec<TypeName>;
pub fn type_name1_c1(
    _ctx: &Ctx,
    mut type_name1: TypeName1,
    type_name: TypeName,
) -> TypeName1 {
    type_name1.push(type_name);
    type_name1
}
pub fn type_name1_type_name(_ctx: &Ctx, type_name: TypeName) -> TypeName1 {
    vec![type_name]
}
#[derive(Debug, Clone)]
pub enum CardinalityOp {
    Plus,
    Star,
}
pub fn cardinality_op_plus(_ctx: &Ctx) -> CardinalityOp {
    CardinalityOp::Plus
}
pub fn cardinality_op_star(_ctx: &Ctx) -> CardinalityOp {
    CardinalityOp::Star
}
#[derive(Debug, Clone)]
pub struct UserDefined {
    pub name: Ident,
}
#[derive(Debug, Clone)]
pub enum TypeName {
    UserDefined(UserDefined),
    String,
    Int64,
    Real64,
    Bool,
    Date,
    Time,
    DateTime,
}
pub fn type_name_user_defined(_ctx: &Ctx, name: Ident) -> TypeName {
    TypeName::UserDefined(UserDefined { name })
}
pub fn type_name_string(_ctx: &Ctx) -> TypeName {
    TypeName::String
}
pub fn type_name_int64(_ctx: &Ctx) -> TypeName {
    TypeName::Int64
}
pub fn type_name_real64(_ctx: &Ctx) -> TypeName {
    TypeName::Real64
}
pub fn type_name_bool(_ctx: &Ctx) -> TypeName {
    TypeName::Bool
}
pub fn type_name_date(_ctx: &Ctx) -> TypeName {
    TypeName::Date
}
pub fn type_name_time(_ctx: &Ctx) -> TypeName {
    TypeName::Time
}
pub fn type_name_date_time(_ctx: &Ctx) -> TypeName {
    TypeName::DateTime
}
#[derive(Debug, Clone)]
pub struct Directive {
    pub name: Ident,
    pub suffix: DirectiveSuffix,
}
#[derive(Debug, Clone)]
pub struct BareDirective {
    pub name: Ident,
}
#[derive(Debug, Clone)]
pub struct FieldRef {
    pub ref_path: FieldPath,
}
#[derive(Debug, Clone)]
pub struct StringLit {
    pub value: StringLiteral,
}
#[derive(Debug, Clone)]
pub struct ConditionalRef {
    pub ref_path: FieldPath,
    pub block: BlockBodyOpt,
}
#[derive(Debug, Clone)]
pub struct ConditionalDirective {
    pub name: Ident,
    pub suffix: DirectiveSuffix,
    pub block: BlockBodyOpt,
}
#[derive(Debug, Clone)]
pub enum RenderExpr {
    ConditionalDirective(ConditionalDirective),
    Directive(Directive),
    BareDirective(BareDirective),
    ConditionalRef(ConditionalRef),
    FieldRef(FieldRef),
    StringLit(StringLit),
}
pub fn render_expr_conditional_directive(
    _ctx: &Ctx,
    name: Ident,
    suffix: DirectiveSuffix,
    block: BlockBodyOpt,
) -> RenderExpr {
    RenderExpr::ConditionalDirective(ConditionalDirective {
        name,
        suffix,
        block,
    })
}
pub fn render_expr_directive(
    _ctx: &Ctx,
    name: Ident,
    suffix: DirectiveSuffix,
) -> RenderExpr {
    RenderExpr::Directive(Directive { name, suffix })
}
pub fn render_expr_bare_directive(_ctx: &Ctx, name: Ident) -> RenderExpr {
    RenderExpr::BareDirective(BareDirective { name })
}
pub fn render_expr_conditional_ref(
    _ctx: &Ctx,
    ref_path: FieldPath,
    block: BlockBodyOpt,
) -> RenderExpr {
    RenderExpr::ConditionalRef(ConditionalRef { ref_path, block })
}
pub fn render_expr_field_ref(_ctx: &Ctx, ref_path: FieldPath) -> RenderExpr {
    RenderExpr::FieldRef(FieldRef { ref_path })
}
pub fn render_expr_string_lit(_ctx: &Ctx, value: StringLiteral) -> RenderExpr {
    RenderExpr::StringLit(StringLit { value })
}
#[derive(Debug, Clone)]
pub struct FieldPath {
    pub segments: Ident1,
}
pub fn field_path_c1(_ctx: &Ctx, segments: Ident1) -> FieldPath {
    FieldPath { segments }
}
#[derive(Debug, Clone)]
pub struct WithArgs {
    pub args: Argument1,
    pub block: BlockBodyOpt,
}
#[derive(Debug, Clone)]
pub struct EmptyParen {
    pub block: BlockBodyOpt,
}
#[derive(Debug, Clone)]
pub enum DirectiveSuffix {
    WithArgs(WithArgs),
    EmptyParen(EmptyParen),
}
pub fn directive_suffix_with_args(
    _ctx: &Ctx,
    args: Argument1,
    block: BlockBodyOpt,
) -> DirectiveSuffix {
    DirectiveSuffix::WithArgs(WithArgs { args, block })
}
pub fn directive_suffix_empty_paren(_ctx: &Ctx, block: BlockBodyOpt) -> DirectiveSuffix {
    DirectiveSuffix::EmptyParen(EmptyParen { block })
}
pub type Argument1 = Vec<Argument>;
pub fn argument1_c1(
    _ctx: &Ctx,
    mut argument1: Argument1,
    argument: Argument,
) -> Argument1 {
    argument1.push(argument);
    argument1
}
pub fn argument1_argument(_ctx: &Ctx, argument: Argument) -> Argument1 {
    vec![argument]
}
pub type BlockBodyOpt = Option<BlockBody>;
pub fn block_body_opt_block_body(_ctx: &Ctx, block_body: BlockBody) -> BlockBodyOpt {
    Some(block_body)
}
pub fn block_body_opt_empty(_ctx: &Ctx) -> BlockBodyOpt {
    None
}
#[derive(Debug, Clone)]
pub struct BlockBody {
    pub items: RenderExpr1,
}
pub fn block_body_c1(_ctx: &Ctx, items: RenderExpr1) -> BlockBody {
    BlockBody { items }
}
pub type RenderExpr1 = Vec<Box<RenderExpr>>;
pub fn render_expr1_c1(
    _ctx: &Ctx,
    mut render_expr1: RenderExpr1,
    render_expr: RenderExpr,
) -> RenderExpr1 {
    render_expr1.push(Box::new(render_expr));
    render_expr1
}
pub fn render_expr1_render_expr(_ctx: &Ctx, render_expr: RenderExpr) -> RenderExpr1 {
    vec![Box::new(render_expr)]
}
#[derive(Debug, Clone)]
pub struct IdentArg {
    pub val: Ident,
}
#[derive(Debug, Clone)]
pub struct LiteralArg {
    pub val: StringLiteral,
}
#[derive(Debug, Clone)]
pub enum Argument {
    IdentArg(IdentArg),
    LiteralArg(LiteralArg),
}
pub fn argument_ident_arg(_ctx: &Ctx, val: Ident) -> Argument {
    Argument::IdentArg(IdentArg { val })
}
pub fn argument_literal_arg(_ctx: &Ctx, val: StringLiteral) -> Argument {
    Argument::LiteralArg(LiteralArg { val })
}