/
ast.ts
85 lines (70 loc) · 1.58 KB
/
ast.ts
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
/**
* Raw messages are `{value, attributes}` shapes containing translation units
* called `Patterns`. `Patterns` are implementation-specific; they should be
* treated as black boxes and formatted with `FluentBundle.formatPattern`.
*/
export type Message = {
id: string;
value: Pattern | null;
attributes: Record<string, Pattern>;
};
export type Term = {
id: string;
value: Pattern;
attributes: Record<string, Pattern>;
};
export type Pattern = string | ComplexPattern;
export type ComplexPattern = Array<PatternElement>;
export type PatternElement = string | Expression;
export type Expression =
| SelectExpression
| VariableReference
| TermReference
| MessageReference
| FunctionReference
| Literal;
export type SelectExpression = {
type: "select";
selector: Expression;
variants: Array<Variant>;
star: number;
};
export type VariableReference = {
type: "var";
name: string;
};
export type TermReference = {
type: "term";
name: string;
attr: string | null;
args: Array<Expression | NamedArgument>;
};
export type MessageReference = {
type: "mesg";
name: string;
attr: string | null;
};
export type FunctionReference = {
type: "func";
name: string;
args: Array<Expression | NamedArgument>;
};
export type Variant = {
key: Literal;
value: Pattern;
};
export type NamedArgument = {
type: "narg";
name: string;
value: Literal;
};
export type Literal = StringLiteral | NumberLiteral;
export type StringLiteral = {
type: "str";
value: string;
};
export type NumberLiteral = {
type: "num";
value: number;
precision: number;
};