fluent_bundle/resolver/
mod.rs

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.
5
6pub mod errors;
7mod expression;
8mod inline_expression;
9mod pattern;
10mod scope;
11
12pub use errors::ResolverError;
13pub use scope::Scope;
14
15use std::borrow::Borrow;
16use std::fmt;
17
18use crate::memoizer::MemoizerKind;
19use crate::resource::FluentResource;
20use crate::types::FluentValue;
21
22/// Resolves an AST node to a [`FluentValue`].
23pub(crate) trait ResolveValue<'bundle> {
24    /// Resolves an AST node to a [`FluentValue`].
25    fn resolve<'ast, 'args, 'errors, R, M>(
26        &'ast self,
27        scope: &mut Scope<'bundle, 'ast, 'args, 'errors, R, M>,
28    ) -> FluentValue<'bundle>
29    where
30        R: Borrow<FluentResource>,
31        M: MemoizerKind;
32}
33
34/// Resolves an AST node to a string that is written to source `W`.
35pub(crate) trait WriteValue<'bundle> {
36    /// Resolves an AST node to a string that is written to source `W`.
37    fn write<'ast, 'args, 'errors, W, R, M>(
38        &'ast self,
39        w: &mut W,
40        scope: &mut Scope<'bundle, 'ast, 'args, 'errors, R, M>,
41    ) -> fmt::Result
42    where
43        W: fmt::Write,
44        R: Borrow<FluentResource>,
45        M: MemoizerKind;
46
47    /// Writes error information to `W`. This can be used to add FTL errors inline
48    /// to a message.
49    fn write_error<W>(&self, _w: &mut W) -> fmt::Result
50    where
51        W: fmt::Write;
52}