1
1
//! The `resolver` module contains the definitions and implementations for the internal
2
- //! `ResolveValue ` and `WriteValue ` traits. The former converts AST nodes to a
3
- //! [`FluentValue`], and the latter converts them to a string that is written to an
4
- //! implementor of the [`std::fmt::Write`] trait.
2
+ //! `WriteOrResolve ` and `WriteOrResolveContext ` traits.
3
+ //! There is an implementation that resolves AST nodes to a [`FluentValue`], and one
4
+ //! that writes to an implementor of the [`std::fmt::Write`] trait.
5
5
6
6
pub mod errors;
7
7
mod expression;
8
8
mod inline_expression;
9
- pub mod pattern;
9
+ pub ( crate ) mod pattern;
10
10
mod scope;
11
11
12
12
pub use errors:: ResolverError ;
@@ -21,56 +21,33 @@ use crate::memoizer::MemoizerKind;
21
21
use crate :: resource:: FluentResource ;
22
22
use crate :: types:: FluentValue ;
23
23
24
- /// Resolves an AST node to a [`FluentValue`].
25
- pub ( crate ) trait ResolveValue < ' bundle > {
26
- /// Resolves an AST node to a [`FluentValue`].
27
- fn resolve < ' ast , ' args , ' errors , R , M > (
28
- & ' ast self ,
29
- scope : & mut Scope < ' bundle , ' ast , ' args , ' errors , R , M > ,
30
- ) -> FluentValue < ' bundle >
31
- where
32
- R : Borrow < FluentResource > ,
33
- M : MemoizerKind ;
34
- }
35
-
36
- /// Resolves an AST node to a string that is written to source `W`.
37
- pub ( crate ) trait WriteValue < ' bundle > {
38
- /// Resolves an AST node to a string that is written to source `W`.
39
- fn write < ' ast , ' args , ' errors , W , R , M > (
40
- & ' ast self ,
41
- w : & mut W ,
42
- scope : & mut Scope < ' bundle , ' ast , ' args , ' errors , R , M > ,
43
- ) -> fmt:: Result
44
- where
45
- W : fmt:: Write ,
46
- R : Borrow < FluentResource > ,
47
- M : MemoizerKind ;
48
- }
24
+ use self :: pattern:: { resolve_pattern, write_pattern} ;
49
25
50
26
pub trait WriteOrResolveContext < ' bundle > {
51
27
type Result ;
52
28
53
29
fn unescape ( & mut self , s : & ' bundle str ) -> Self :: Result ;
54
- fn value < ' ast , ' args , ' errors , R , M > (
30
+ fn value < ' other , R , M > (
55
31
& mut self ,
56
- scope : & Scope < ' bundle , ' ast , ' args , ' errors , R , M > ,
32
+ scope : & Scope < ' bundle , ' other , R , M > ,
57
33
value : Cow < FluentValue < ' bundle > > ,
58
34
) -> Self :: Result
59
35
where
60
36
R : Borrow < FluentResource > ,
61
37
M : MemoizerKind ;
62
38
63
39
fn error < E : WriteOrResolve < ' bundle > > ( & mut self , exp : & E , is_ref : bool ) -> Self :: Result ;
64
- fn resolve_pattern < ' ast , ' args , ' errors , R , M > (
40
+ fn resolve_pattern < ' other , R , M > (
65
41
& mut self ,
66
- scope : & mut Scope < ' bundle , ' ast , ' args , ' errors , R , M > ,
67
- pattern : & ' ast ast:: Pattern < & ' bundle str > ,
42
+ scope : & mut Scope < ' bundle , ' other , R , M > ,
43
+ pattern : & ' bundle ast:: Pattern < & ' bundle str > ,
68
44
) -> Self :: Result
69
45
where
70
46
R : Borrow < FluentResource > ,
71
47
M : MemoizerKind ;
72
48
}
73
49
50
+ /// Resolves an AST node to a string that is written to source `W`.
74
51
impl < ' bundle , W > WriteOrResolveContext < ' bundle > for W
75
52
where
76
53
W : fmt:: Write ,
81
58
unescape_unicode ( self , s)
82
59
}
83
60
84
- fn value < ' ast , ' args , ' errors , R , M > (
61
+ fn value < ' other , R , M > (
85
62
& mut self ,
86
- scope : & Scope < ' bundle , ' ast , ' args , ' errors , R , M > ,
63
+ scope : & Scope < ' bundle , ' other , R , M > ,
87
64
value : Cow < FluentValue < ' bundle > > ,
88
65
) -> Self :: Result
89
66
where
@@ -109,19 +86,20 @@ where
109
86
Ok ( ( ) )
110
87
}
111
88
112
- fn resolve_pattern < ' ast , ' args , ' errors , R , M > (
89
+ fn resolve_pattern < ' other , R , M > (
113
90
& mut self ,
114
- scope : & mut Scope < ' bundle , ' ast , ' args , ' errors , R , M > ,
115
- pattern : & ' ast ast:: Pattern < & ' bundle str > ,
91
+ scope : & mut Scope < ' bundle , ' other , R , M > ,
92
+ pattern : & ' bundle ast:: Pattern < & ' bundle str > ,
116
93
) -> Self :: Result
117
94
where
118
95
R : Borrow < FluentResource > ,
119
96
M : MemoizerKind ,
120
97
{
121
- pattern . write ( self , scope)
98
+ write_pattern ( pattern , self , scope)
122
99
}
123
100
}
124
101
102
+ /// Resolves an AST node to a [`FluentValue`].
125
103
struct ResolveContext ;
126
104
127
105
impl < ' bundle > WriteOrResolveContext < ' bundle > for ResolveContext {
@@ -131,9 +109,9 @@ impl<'bundle> WriteOrResolveContext<'bundle> for ResolveContext {
131
109
unescape_unicode_to_string ( s) . into ( )
132
110
}
133
111
134
- fn value < ' ast , ' args , ' errors , R , M > (
112
+ fn value < ' other , R , M > (
135
113
& mut self ,
136
- _scope : & Scope < ' bundle , ' ast , ' args , ' errors , R , M > ,
114
+ _scope : & Scope < ' bundle , ' other , R , M > ,
137
115
value : Cow < FluentValue < ' bundle > > ,
138
116
) -> Self :: Result
139
117
where
@@ -147,23 +125,23 @@ impl<'bundle> WriteOrResolveContext<'bundle> for ResolveContext {
147
125
FluentValue :: Error
148
126
}
149
127
150
- fn resolve_pattern < ' ast , ' args , ' errors , R , M > (
128
+ fn resolve_pattern < ' other , R , M > (
151
129
& mut self ,
152
- scope : & mut Scope < ' bundle , ' ast , ' args , ' errors , R , M > ,
153
- pattern : & ' ast ast:: Pattern < & ' bundle str > ,
130
+ scope : & mut Scope < ' bundle , ' other , R , M > ,
131
+ pattern : & ' bundle ast:: Pattern < & ' bundle str > ,
154
132
) -> Self :: Result
155
133
where
156
134
R : Borrow < FluentResource > ,
157
135
M : MemoizerKind ,
158
136
{
159
- pattern . resolve ( scope)
137
+ resolve_pattern ( pattern , scope)
160
138
}
161
139
}
162
140
163
141
pub trait WriteOrResolve < ' bundle > {
164
- fn write_or_resolve < ' ast , ' args , ' errors , R , M , T > (
165
- & ' ast self ,
166
- scope : & mut Scope < ' bundle , ' ast , ' args , ' errors , R , M > ,
142
+ fn write_or_resolve < ' other , R , M , T > (
143
+ & ' bundle self ,
144
+ scope : & mut Scope < ' bundle , ' other , R , M > ,
167
145
context : & mut T ,
168
146
) -> T :: Result
169
147
where
0 commit comments