|
| 1 | +use smallvec::SmallVec; |
| 2 | + |
| 3 | +#[derive(Debug, PartialEq)] |
| 4 | +pub struct Message<S> { |
| 5 | + pub declarations: SmallVec<[Declaration<S>; 1]>, |
| 6 | + pub value: MessageValue<S>, |
| 7 | +} |
| 8 | + |
| 9 | +#[derive(Debug, PartialEq)] |
| 10 | +pub struct Declaration<S> { |
| 11 | + pub variable: S, |
| 12 | + pub expression: Expression<S>, |
| 13 | +} |
| 14 | + |
| 15 | +#[derive(Debug, PartialEq)] |
| 16 | +pub enum MessageValue<S> { |
| 17 | + Pattern(Pattern<S>), |
| 18 | + Select(Box<Select<S>>), |
| 19 | +} |
| 20 | + |
| 21 | +#[derive(Debug, PartialEq)] |
| 22 | +pub struct Select<S> { |
| 23 | + pub selector: SmallVec<[Expression<S>; 1]>, |
| 24 | + pub variants: SmallVec<[Variant<S>; 3]>, |
| 25 | +} |
| 26 | + |
| 27 | +#[derive(Debug, PartialEq)] |
| 28 | +pub struct Variant<S> { |
| 29 | + pub key: SmallVec<[VariantKey<S>; 1]>, |
| 30 | + pub pattern: Pattern<S>, |
| 31 | +} |
| 32 | + |
| 33 | +#[derive(Debug, PartialEq)] |
| 34 | +pub struct Pattern<S> { |
| 35 | + pub body: SmallVec<[PatternElement<S>; 3]>, |
| 36 | +} |
| 37 | + |
| 38 | +#[derive(Debug, PartialEq)] |
| 39 | +pub enum PatternElement<S> { |
| 40 | + Text(S), |
| 41 | + Placeholder(Placeholder<S>), |
| 42 | +} |
| 43 | + |
| 44 | +#[derive(Debug, PartialEq)] |
| 45 | +pub enum Placeholder<S> { |
| 46 | + Markup { |
| 47 | + name: S, |
| 48 | + options: SmallVec<[Option<S>; 1]>, |
| 49 | + }, |
| 50 | + MarkupEnd { |
| 51 | + name: S, |
| 52 | + }, |
| 53 | + Expression(Expression<S>), |
| 54 | +} |
| 55 | + |
| 56 | +#[derive(Debug, PartialEq)] |
| 57 | +pub enum Expression<S> { |
| 58 | + Operand { |
| 59 | + operand: Operand<S>, |
| 60 | + annotation: std::option::Option<Annotation<S>>, |
| 61 | + }, |
| 62 | + Annotation(Annotation<S>), |
| 63 | +} |
| 64 | + |
| 65 | +#[derive(Debug, PartialEq)] |
| 66 | +pub enum Operand<S> { |
| 67 | + Literal(Literal<S>), |
| 68 | + Variable(S), |
| 69 | +} |
| 70 | + |
| 71 | +#[derive(Debug, PartialEq)] |
| 72 | +pub struct Annotation<S> { |
| 73 | + function: S, |
| 74 | + options: SmallVec<[Option<S>; 1]>, |
| 75 | +} |
| 76 | + |
| 77 | +#[derive(Debug, PartialEq)] |
| 78 | +pub struct Literal<S> { |
| 79 | + pub value: S, |
| 80 | +} |
| 81 | + |
| 82 | +#[derive(Debug, PartialEq)] |
| 83 | +pub enum VariantKey<S> { |
| 84 | + Literal(Literal<S>), |
| 85 | + Asterisk, |
| 86 | +} |
| 87 | + |
| 88 | +#[derive(Debug, PartialEq)] |
| 89 | +pub struct Option<S> { |
| 90 | + name: S, |
| 91 | + value: OptionValue<S>, |
| 92 | +} |
| 93 | + |
| 94 | +#[derive(Debug, PartialEq)] |
| 95 | +pub enum OptionValue<S> { |
| 96 | + Literal(Literal<S>), |
| 97 | + Variable(S), |
| 98 | +} |
0 commit comments