Skip to content

Commit 9fac18a

Browse files
committed
Document resolvers in the fluent-bundle
1 parent 41223f9 commit 9fac18a

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

fluent-bundle/src/resolver/errors.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use fluent_syntax::ast::InlineExpression;
22
use std::error::Error;
33

4+
/// Maps an [`InlineExpression`] into the kind of reference, with owned strings
5+
/// that identify the expression. This makes it so that the [`InlineExpression`] can
6+
/// be used to generate an error string.
47
#[derive(Debug, PartialEq, Clone)]
58
pub enum ReferenceKind {
69
Function {
@@ -44,6 +47,8 @@ where
4447
}
4548
}
4649

50+
/// Errors generated during the process of resolving a fluent message into a string.
51+
/// This process takes place in the `write` method of the `WriteValue` trait.
4752
#[derive(Debug, PartialEq, Clone)]
4853
pub enum ResolverError {
4954
Reference(ReferenceKind),

fluent-bundle/src/resolver/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
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+
16
pub mod errors;
27
mod expression;
38
mod inline_expression;
@@ -14,8 +19,9 @@ use crate::memoizer::MemoizerKind;
1419
use crate::resource::FluentResource;
1520
use crate::types::FluentValue;
1621

17-
// Converts an AST node to a `FluentValue`.
22+
/// Resolves an AST node to a [`FluentValue`].
1823
pub(crate) trait ResolveValue<'bundle> {
24+
/// Resolves an AST node to a [`FluentValue`].
1925
fn resolve<'ast, 'args, 'errors, R, M>(
2026
&'ast self,
2127
scope: &mut Scope<'bundle, 'ast, 'args, 'errors, R, M>,
@@ -25,7 +31,9 @@ pub(crate) trait ResolveValue<'bundle> {
2531
M: MemoizerKind;
2632
}
2733

34+
/// Resolves an AST node to a string that is written to source `W`.
2835
pub(crate) trait WriteValue<'bundle> {
36+
/// Resolves an AST node to a string that is written to source `W`.
2937
fn write<'ast, 'args, 'errors, W, R, M>(
3038
&'ast self,
3139
w: &mut W,
@@ -36,6 +44,8 @@ pub(crate) trait WriteValue<'bundle> {
3644
R: Borrow<FluentResource>,
3745
M: MemoizerKind;
3846

47+
/// Writes error information to `W`. This can be used to add FTL errors inline
48+
/// to a message.
3949
fn write_error<W>(&self, _w: &mut W) -> fmt::Result
4050
where
4151
W: fmt::Write;

fluent-bundle/src/resolver/scope.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ impl<'bundle, 'ast, 'args, 'errors, R, M> Scope<'bundle, 'ast, 'args, 'errors, R
4949
}
5050
}
5151

52-
// This method allows us to lazily add Pattern on the stack,
53-
// only if the Pattern::resolve has been called on an empty stack.
54-
//
55-
// This is the case when pattern is called from Bundle and it
56-
// allows us to fast-path simple resolutions, and only use the stack
57-
// for placeables.
52+
/// This method allows us to lazily add Pattern on the stack, only if the
53+
/// Pattern::resolve has been called on an empty stack.
54+
///
55+
/// This is the case when pattern is called from Bundle and it allows us to fast-path
56+
/// simple resolutions, and only use the stack for placeables.
5857
pub fn maybe_track<W>(
5958
&mut self,
6059
w: &mut W,

0 commit comments

Comments
 (0)