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
#[derive(Debug, PartialEq)]
pub struct Resource {
    pub body: Vec<Entry>,
    pub comment: Option<Comment>,
}

#[derive(Debug, PartialEq)]
pub enum Entry {
    Message(Message),
    Section {
        name: Symbol,
        comment: Option<Comment>,
    },
    Comment(Comment),
    Junk { content: String },
}

#[derive(Debug, PartialEq)]
pub struct Message {
    pub id: Identifier,
    pub value: Option<Pattern>,
    pub attributes: Option<Vec<Attribute>>,
    pub tags: Option<Vec<Tag>>,
    pub comment: Option<Comment>,
}

#[derive(Debug, PartialEq)]
pub struct Pattern {
    pub elements: Vec<PatternElement>,
}

#[derive(Debug, PartialEq)]
pub enum PatternElement {
    TextElement(String),
    Placeable(Placeable),
}

#[derive(Debug, PartialEq)]
pub struct Placeable {
    pub expression: Expression,
}

#[derive(Debug, PartialEq)]
pub enum Expression {
    StringExpression { value: String },
    NumberExpression { value: Number },
    MessageReference { id: Identifier },
    ExternalArgument { id: Identifier },
    SelectExpression {
        expression: Option<Box<Expression>>,
        variants: Vec<Variant>,
    },
    AttributeExpression { id: Identifier, name: Identifier },
    VariantExpression { id: Identifier, key: VarKey },
    CallExpression {
        callee: Function,
        args: Vec<Argument>,
    },
}

#[derive(Debug, PartialEq)]
pub struct Attribute {
    pub id: Identifier,
    pub value: Pattern,
}

#[derive(Debug, PartialEq)]
pub struct Tag {
    pub name: Symbol,
}

#[derive(Debug, PartialEq)]
pub struct Variant {
    pub key: VarKey,
    pub value: Pattern,
    pub default: bool,
}

#[derive(Debug, PartialEq)]
pub enum VarKey {
    Symbol(Symbol),
    Number(Number),
}

#[derive(Debug, PartialEq)]
pub enum Argument {
    Expression(Expression),
    NamedArgument { name: Identifier, val: ArgValue },
}

#[derive(Debug, PartialEq)]
pub enum ArgValue {
    Number(Number),
    String(String),
}

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


#[derive(Debug, PartialEq)]
pub struct Number {
    pub value: String,
}

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

#[derive(Debug, PartialEq)]
pub struct Comment {
    pub content: String,
}

#[derive(Debug, PartialEq)]
pub struct Section {
    pub name: String,
    pub comment: Option<Comment>,
}

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