Skip to main content

linguini_ir/
model.rs

1pub use linguini_core::FormatterKind as IrFormatterKind;
2
3#[derive(Debug, Clone, PartialEq, Eq, Default)]
4pub struct IrModule {
5    pub enums: Vec<IrEnum>,
6    pub type_aliases: Vec<IrTypeAlias>,
7    pub variables: Vec<IrVariable>,
8    pub messages: Vec<IrMessage>,
9    pub forms: Vec<IrForm>,
10    pub functions: Vec<IrFunction>,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct IrTypeAlias {
15    pub name: String,
16    pub target: String,
17    pub docs: Vec<String>,
18    pub formatters: Vec<IrFormatter>,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub struct IrEnum {
23    pub name: String,
24    pub docs: Vec<String>,
25    pub variants: Vec<String>,
26}
27
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct IrMessage {
30    pub name: String,
31    pub docs: Vec<String>,
32    pub parameters: Vec<IrParameter>,
33    pub body: Option<IrText>,
34}
35
36#[derive(Debug, Clone, PartialEq, Eq)]
37pub struct IrParameter {
38    pub name: String,
39    pub ty: String,
40}
41
42#[derive(Debug, Clone, PartialEq, Eq)]
43pub struct IrVariable {
44    pub name: String,
45    pub docs: Vec<String>,
46    pub value: IrText,
47}
48
49#[derive(Debug, Clone, PartialEq, Eq)]
50pub struct IrForm {
51    pub name: String,
52    pub docs: Vec<String>,
53    pub variants: Vec<IrFormVariant>,
54}
55
56#[derive(Debug, Clone, PartialEq, Eq)]
57pub struct IrFormVariant {
58    pub name: String,
59    pub entries: Vec<IrFormEntry>,
60}
61
62#[derive(Debug, Clone, PartialEq, Eq)]
63pub enum IrFormEntry {
64    Attribute { name: String, value: IrValue },
65    Branch(IrBranch),
66}
67
68#[derive(Debug, Clone, PartialEq, Eq)]
69pub enum IrValue {
70    Text(IrText),
71    Map(Vec<IrBranch>),
72    Object(Vec<IrFormEntry>),
73}
74
75#[derive(Debug, Clone, PartialEq, Eq)]
76pub struct IrFunction {
77    pub name: String,
78    pub docs: Vec<String>,
79    pub parameters: Vec<IrFunctionParameter>,
80    pub branches: Vec<IrFunctionBranch>,
81}
82
83#[derive(Debug, Clone, PartialEq, Eq)]
84pub struct IrFunctionParameter {
85    pub name: Option<String>,
86    pub ty: String,
87}
88
89#[derive(Debug, Clone, PartialEq, Eq)]
90pub struct IrFunctionBranch {
91    pub key: String,
92    pub value: IrFunctionBranchValue,
93}
94
95#[derive(Debug, Clone, PartialEq, Eq)]
96pub enum IrFunctionBranchValue {
97    Text(IrText),
98    Dispatch(Vec<IrFunctionBranch>),
99}
100
101#[derive(Debug, Clone, PartialEq, Eq)]
102pub struct IrBranch {
103    pub keys: Vec<String>,
104    pub value: IrText,
105}
106
107#[derive(Debug, Clone, PartialEq, Eq)]
108pub struct IrText {
109    pub parts: Vec<IrTextPart>,
110}
111
112#[derive(Debug, Clone, PartialEq, Eq)]
113pub enum IrTextPart {
114    Text(String),
115    Placeholder(IrExpression),
116}
117
118#[derive(Debug, Clone, PartialEq, Eq)]
119pub struct IrExpression {
120    pub path: Vec<String>,
121    pub arguments: Vec<IrExpression>,
122    pub formatters: Vec<IrFormatter>,
123}
124
125#[derive(Debug, Clone, PartialEq, Eq)]
126pub struct IrFormatter {
127    pub kind: IrFormatterKind,
128    pub arguments: Vec<IrFormatterArgument>,
129}
130
131#[derive(Debug, Clone, PartialEq, Eq)]
132pub struct IrFormatterArgument {
133    pub name: String,
134    pub value: String,
135}