fen_parser/
ast.rs

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
use serde::Serialize;

#[derive(Debug, PartialEq, Eq, Serialize, Clone)]
pub struct FileNode {
    // metadata
    pub name: String,
    pub description: Option<String>,
    pub authed: bool,

    // i/o
    pub input: Option<IOType>,
    pub output: Option<IOType>,

    // helper types
    pub structs: Vec<StructDefinition>,
    pub enums: Vec<EnumDefinition>,
}

#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize)]
#[serde(tag = "type")]
pub enum Primitive {
    Int,
    Float,
    String,
    Bool,
    Date,
    Uuid,
}

#[derive(Debug, PartialEq, Eq, Serialize, Clone)]
pub enum Type {
    Named(String),
    Optional(Box<Type>),
    Array(Box<Type>),
    Primitive(Primitive),
}

#[derive(Debug, PartialEq, Eq, Serialize, Clone)]
pub struct StructDefinition {
    pub name: String,
    pub fields: Vec<Field>,
    pub annotations: Vec<String>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Clone)]
pub struct Field {
    pub name: String,
    #[serde(rename = "type")]
    pub t: Type,
}

#[derive(Debug, PartialEq, Eq, Serialize, Clone)]
pub struct EnumDefinition {
    pub name: String,
    pub variants: Vec<Variant>,
    pub annotations: Vec<String>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Clone)]
pub struct Variant {
    pub name: String,
    #[serde(rename = "type")]
    pub t: Option<Type>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Clone)]
pub enum IOType {
    Type(Type),
    Struct(StructDefinition),
    Enum(EnumDefinition),
}