11//! 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.
55
66pub mod errors;
77mod expression;
88mod inline_expression;
9- pub mod pattern;
9+ pub ( crate ) mod pattern;
1010mod scope;
1111
1212pub use errors:: ResolverError ;
@@ -21,56 +21,33 @@ use crate::memoizer::MemoizerKind;
2121use crate :: resource:: FluentResource ;
2222use crate :: types:: FluentValue ;
2323
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} ;
4925
5026pub trait WriteOrResolveContext < ' bundle > {
5127 type Result ;
5228
5329 fn unescape ( & mut self , s : & ' bundle str ) -> Self :: Result ;
54- fn value < ' ast , ' args , ' errors , R , M > (
30+ fn value < ' other , R , M > (
5531 & mut self ,
56- scope : & Scope < ' bundle , ' ast , ' args , ' errors , R , M > ,
32+ scope : & Scope < ' bundle , ' other , R , M > ,
5733 value : Cow < FluentValue < ' bundle > > ,
5834 ) -> Self :: Result
5935 where
6036 R : Borrow < FluentResource > ,
6137 M : MemoizerKind ;
6238
6339 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 > (
6541 & 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 > ,
6844 ) -> Self :: Result
6945 where
7046 R : Borrow < FluentResource > ,
7147 M : MemoizerKind ;
7248}
7349
50+ /// Resolves an AST node to a string that is written to source `W`.
7451impl < ' bundle , W > WriteOrResolveContext < ' bundle > for W
7552where
7653 W : fmt:: Write ,
8158 unescape_unicode ( self , s)
8259 }
8360
84- fn value < ' ast , ' args , ' errors , R , M > (
61+ fn value < ' other , R , M > (
8562 & mut self ,
86- scope : & Scope < ' bundle , ' ast , ' args , ' errors , R , M > ,
63+ scope : & Scope < ' bundle , ' other , R , M > ,
8764 value : Cow < FluentValue < ' bundle > > ,
8865 ) -> Self :: Result
8966 where
@@ -109,19 +86,20 @@ where
10986 Ok ( ( ) )
11087 }
11188
112- fn resolve_pattern < ' ast , ' args , ' errors , R , M > (
89+ fn resolve_pattern < ' other , R , M > (
11390 & 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 > ,
11693 ) -> Self :: Result
11794 where
11895 R : Borrow < FluentResource > ,
11996 M : MemoizerKind ,
12097 {
121- pattern . write ( self , scope)
98+ write_pattern ( pattern , self , scope)
12299 }
123100}
124101
102+ /// Resolves an AST node to a [`FluentValue`].
125103struct ResolveContext ;
126104
127105impl < ' bundle > WriteOrResolveContext < ' bundle > for ResolveContext {
@@ -131,9 +109,9 @@ impl<'bundle> WriteOrResolveContext<'bundle> for ResolveContext {
131109 unescape_unicode_to_string ( s) . into ( )
132110 }
133111
134- fn value < ' ast , ' args , ' errors , R , M > (
112+ fn value < ' other , R , M > (
135113 & mut self ,
136- _scope : & Scope < ' bundle , ' ast , ' args , ' errors , R , M > ,
114+ _scope : & Scope < ' bundle , ' other , R , M > ,
137115 value : Cow < FluentValue < ' bundle > > ,
138116 ) -> Self :: Result
139117 where
@@ -147,23 +125,23 @@ impl<'bundle> WriteOrResolveContext<'bundle> for ResolveContext {
147125 FluentValue :: Error
148126 }
149127
150- fn resolve_pattern < ' ast , ' args , ' errors , R , M > (
128+ fn resolve_pattern < ' other , R , M > (
151129 & 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 > ,
154132 ) -> Self :: Result
155133 where
156134 R : Borrow < FluentResource > ,
157135 M : MemoizerKind ,
158136 {
159- pattern . resolve ( scope)
137+ resolve_pattern ( pattern , scope)
160138 }
161139}
162140
163141pub 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 > ,
167145 context : & mut T ,
168146 ) -> T :: Result
169147 where
0 commit comments