|  | 
| 1 | 1 | #[derive(Debug, PartialEq)] | 
| 2 |  | -pub struct Resource { | 
| 3 |  | -    pub body: Vec<Entry>, | 
|  | 2 | +pub struct Resource<'ast> { | 
|  | 3 | +    pub body: Vec<ResourceEntry<'ast>>, | 
| 4 | 4 | } | 
| 5 | 5 | 
 | 
| 6 | 6 | #[derive(Debug, PartialEq)] | 
| 7 |  | -pub enum Entry { | 
| 8 |  | -    Message(Message), | 
| 9 |  | -    Term(Term), | 
| 10 |  | -    Comment(Comment), | 
| 11 |  | -    Junk { content: String }, | 
|  | 7 | +pub enum ResourceEntry<'ast> { | 
|  | 8 | +    Entry(Entry<'ast>), | 
|  | 9 | +    Junk(&'ast str), | 
| 12 | 10 | } | 
| 13 | 11 | 
 | 
| 14 | 12 | #[derive(Debug, PartialEq)] | 
| 15 |  | -pub struct Message { | 
| 16 |  | -    pub id: Identifier, | 
| 17 |  | -    pub value: Option<Pattern>, | 
| 18 |  | -    pub attributes: Option<Vec<Attribute>>, | 
| 19 |  | -    pub comment: Option<Comment>, | 
|  | 13 | +pub enum Entry<'ast> { | 
|  | 14 | +    Message(Message<'ast>), | 
|  | 15 | +    Term(Term<'ast>), | 
|  | 16 | +    Comment(Comment<'ast>), | 
| 20 | 17 | } | 
| 21 | 18 | 
 | 
| 22 | 19 | #[derive(Debug, PartialEq)] | 
| 23 |  | -pub struct Term { | 
| 24 |  | -    pub id: Identifier, | 
| 25 |  | -    pub value: Pattern, | 
| 26 |  | -    pub attributes: Option<Vec<Attribute>>, | 
| 27 |  | -    pub comment: Option<Comment>, | 
|  | 20 | +pub struct Message<'ast> { | 
|  | 21 | +    pub id: Identifier<'ast>, | 
|  | 22 | +    pub value: Option<Pattern<'ast>>, | 
|  | 23 | +    pub attributes: Vec<Attribute<'ast>>, | 
|  | 24 | +    pub comment: Option<Comment<'ast>>, | 
| 28 | 25 | } | 
| 29 | 26 | 
 | 
| 30 | 27 | #[derive(Debug, PartialEq)] | 
| 31 |  | -pub struct Pattern { | 
| 32 |  | -    pub elements: Vec<PatternElement>, | 
|  | 28 | +pub struct Term<'ast> { | 
|  | 29 | +    pub id: Identifier<'ast>, | 
|  | 30 | +    pub value: Value<'ast>, | 
|  | 31 | +    pub attributes: Vec<Attribute<'ast>>, | 
|  | 32 | +    pub comment: Option<Comment<'ast>>, | 
| 33 | 33 | } | 
| 34 | 34 | 
 | 
| 35 | 35 | #[derive(Debug, PartialEq)] | 
| 36 |  | -pub enum PatternElement { | 
| 37 |  | -    TextElement(String), | 
| 38 |  | -    Placeable(Expression), | 
|  | 36 | +pub enum Value<'ast> { | 
|  | 37 | +    Pattern(Pattern<'ast>), | 
|  | 38 | +    VariantList { variants: Vec<Variant<'ast>> }, | 
| 39 | 39 | } | 
| 40 | 40 | 
 | 
| 41 | 41 | #[derive(Debug, PartialEq)] | 
| 42 |  | -pub enum Expression { | 
| 43 |  | -    StringExpression { | 
| 44 |  | -        value: String, | 
| 45 |  | -    }, | 
| 46 |  | -    NumberExpression { | 
| 47 |  | -        value: Number, | 
| 48 |  | -    }, | 
| 49 |  | -    MessageReference { | 
| 50 |  | -        id: Identifier, | 
| 51 |  | -    }, | 
| 52 |  | -    ExternalArgument { | 
| 53 |  | -        id: Identifier, | 
| 54 |  | -    }, | 
| 55 |  | -    SelectExpression { | 
| 56 |  | -        expression: Option<Box<Expression>>, | 
| 57 |  | -        variants: Vec<Variant>, | 
| 58 |  | -    }, | 
| 59 |  | -    AttributeExpression { | 
| 60 |  | -        id: Identifier, | 
| 61 |  | -        name: Identifier, | 
| 62 |  | -    }, | 
| 63 |  | -    VariantExpression { | 
| 64 |  | -        id: Identifier, | 
| 65 |  | -        key: VarKey, | 
| 66 |  | -    }, | 
| 67 |  | -    CallExpression { | 
| 68 |  | -        callee: Function, | 
| 69 |  | -        args: Vec<Argument>, | 
| 70 |  | -    }, | 
|  | 42 | +pub struct Pattern<'ast> { | 
|  | 43 | +    pub elements: Vec<PatternElement<'ast>>, | 
| 71 | 44 | } | 
| 72 | 45 | 
 | 
| 73 | 46 | #[derive(Debug, PartialEq)] | 
| 74 |  | -pub struct Attribute { | 
| 75 |  | -    pub id: Identifier, | 
| 76 |  | -    pub value: Pattern, | 
|  | 47 | +pub enum PatternElement<'ast> { | 
|  | 48 | +    TextElement(&'ast str), | 
|  | 49 | +    Placeable(Expression<'ast>), | 
| 77 | 50 | } | 
| 78 | 51 | 
 | 
| 79 | 52 | #[derive(Debug, PartialEq)] | 
| 80 |  | -pub struct Variant { | 
| 81 |  | -    pub key: VarKey, | 
| 82 |  | -    pub value: Pattern, | 
| 83 |  | -    pub default: bool, | 
|  | 53 | +pub struct Attribute<'ast> { | 
|  | 54 | +    pub id: Identifier<'ast>, | 
|  | 55 | +    pub value: Pattern<'ast>, | 
| 84 | 56 | } | 
| 85 | 57 | 
 | 
| 86 | 58 | #[derive(Debug, PartialEq)] | 
| 87 |  | -pub enum VarKey { | 
| 88 |  | -    VariantName(VariantName), | 
| 89 |  | -    Number(Number), | 
|  | 59 | +pub struct Identifier<'ast> { | 
|  | 60 | +    pub name: &'ast str, | 
| 90 | 61 | } | 
| 91 | 62 | 
 | 
| 92 | 63 | #[derive(Debug, PartialEq)] | 
| 93 |  | -pub enum Argument { | 
| 94 |  | -    Expression(Expression), | 
| 95 |  | -    NamedArgument { name: Identifier, val: ArgValue }, | 
|  | 64 | +pub struct Function<'ast> { | 
|  | 65 | +    pub name: &'ast str, | 
| 96 | 66 | } | 
| 97 | 67 | 
 | 
| 98 | 68 | #[derive(Debug, PartialEq)] | 
| 99 |  | -pub enum ArgValue { | 
| 100 |  | -    Number(Number), | 
| 101 |  | -    String(String), | 
|  | 69 | +pub struct Variant<'ast> { | 
|  | 70 | +    pub key: VariantKey<'ast>, | 
|  | 71 | +    pub value: Value<'ast>, | 
|  | 72 | +    pub default: bool, | 
| 102 | 73 | } | 
| 103 | 74 | 
 | 
| 104 |  | -#[derive(Debug, PartialEq, Eq, Hash)] | 
| 105 |  | -pub struct Identifier { | 
| 106 |  | -    pub name: String, | 
|  | 75 | +#[derive(Debug, PartialEq)] | 
|  | 76 | +pub enum VariantKey<'ast> { | 
|  | 77 | +    Identifier { name: &'ast str }, | 
|  | 78 | +    NumberLiteral { value: &'ast str }, | 
| 107 | 79 | } | 
| 108 | 80 | 
 | 
| 109 | 81 | #[derive(Debug, PartialEq)] | 
| 110 |  | -pub struct Number { | 
| 111 |  | -    pub value: String, | 
|  | 82 | +pub enum Comment<'ast> { | 
|  | 83 | +    Comment { content: Vec<&'ast str> }, | 
|  | 84 | +    GroupComment { content: Vec<&'ast str> }, | 
|  | 85 | +    ResourceComment { content: Vec<&'ast str> }, | 
| 112 | 86 | } | 
| 113 | 87 | 
 | 
| 114 | 88 | #[derive(Debug, PartialEq)] | 
| 115 |  | -pub struct VariantName { | 
| 116 |  | -    pub name: String, | 
|  | 89 | +pub enum InlineExpression<'ast> { | 
|  | 90 | +    StringLiteral { | 
|  | 91 | +        value: &'ast str, | 
|  | 92 | +    }, | 
|  | 93 | +    NumberLiteral { | 
|  | 94 | +        value: &'ast str, | 
|  | 95 | +    }, | 
|  | 96 | +    VariableReference { | 
|  | 97 | +        id: Identifier<'ast>, | 
|  | 98 | +    }, | 
|  | 99 | +    CallExpression { | 
|  | 100 | +        callee: Function<'ast>, | 
|  | 101 | +        positional: Vec<InlineExpression<'ast>>, | 
|  | 102 | +        named: Vec<NamedArgument<'ast>>, | 
|  | 103 | +    }, | 
|  | 104 | +    AttributeExpression { | 
|  | 105 | +        reference: Box<InlineExpression<'ast>>, | 
|  | 106 | +        name: Identifier<'ast>, | 
|  | 107 | +    }, | 
|  | 108 | +    VariantExpression { | 
|  | 109 | +        reference: Box<InlineExpression<'ast>>, | 
|  | 110 | +        key: VariantKey<'ast>, | 
|  | 111 | +    }, | 
|  | 112 | +    MessageReference { | 
|  | 113 | +        id: Identifier<'ast>, | 
|  | 114 | +    }, | 
|  | 115 | +    TermReference { | 
|  | 116 | +        id: Identifier<'ast>, | 
|  | 117 | +    }, | 
|  | 118 | +    Placeable { | 
|  | 119 | +        expression: Box<Expression<'ast>>, | 
|  | 120 | +    }, | 
| 117 | 121 | } | 
| 118 | 122 | 
 | 
| 119 | 123 | #[derive(Debug, PartialEq)] | 
| 120 |  | -pub enum Comment { | 
| 121 |  | -    Comment { content: String }, | 
| 122 |  | -    GroupComment { content: String }, | 
| 123 |  | -    ResourceComment { content: String }, | 
|  | 124 | +pub struct NamedArgument<'ast> { | 
|  | 125 | +    pub name: Identifier<'ast>, | 
|  | 126 | +    pub value: InlineExpression<'ast>, | 
| 124 | 127 | } | 
| 125 | 128 | 
 | 
| 126 | 129 | #[derive(Debug, PartialEq)] | 
| 127 |  | -pub struct Function { | 
| 128 |  | -    pub name: String, | 
|  | 130 | +pub enum Expression<'ast> { | 
|  | 131 | +    InlineExpression(InlineExpression<'ast>), | 
|  | 132 | +    SelectExpression { | 
|  | 133 | +        selector: InlineExpression<'ast>, | 
|  | 134 | +        variants: Vec<Variant<'ast>>, | 
|  | 135 | +    }, | 
| 129 | 136 | } | 
0 commit comments