Expand description
mf2-model — the Unicode MessageFormat 2 (MF2) interchange data model as
Rust types, plus the identities and error kinds every mf2-two crate shares
and the Frontend trait a parser implements.
The data model’s structs mirror the specification’s message.json field
for field, and code builds them by literal; a later MF2 that defines a
new structure adds a variant, which is why the enums are
#[non_exhaustive].
MsgId,Dir— identities shared with the catalog and the runtime.is_name_start,is_name_char— the ABNF’s name classes, shared by the two frontends.ErrorKind,ErrorClass,Span,Diagnostic,Diagnostics— the 13 error kinds of the WG test suite plus two, and how a frontend reports them.Messageand everything below it — the specification’s interchange data model, one-to-one.Parsed,Frontend— the parser boundary.
Values are kept as written: nothing in this crate normalizes. Names
exclude the bidi marks the syntax allows around them (spec, “Names and
Identifiers”); equality is exact (bytewise), which is what the round-trip
properties of the conformance tests need. Normalization belongs to
comparison (validation in mf2-syntax) and to catalog encoding.
#![no_std] + alloc, no dependencies by default. Features: serde (JSON
that validates against the specification’s message.json) and suite-names (error kinds ↔ the
suite’s strings). The client wasm links only MsgId, Dir and
ErrorKind.
§The user guide
Getting started, call sites, delivery modes, switching language,
accessibility, migrating from leptos-fluent, and what 1.x promises
(versioning.md): the user guide is the docs/ directory of the
mf2-two repository. An application formatting messages starts at
mf2; this crate is for tools that work on the
data model itself, with mf2-syntax.
Structs§
- Attributes
- The attributes of an expression or markup, in source order; a
Nonevalue is the spec’strue(an attribute written without a value). - Catch
AllKey - The catch-all key. Its
valuelets other formats keep an identifier; it is alwaysNonefrom MF2 syntax, where the key is written*. - Diagnostic
- One reported error. Made with
Diagnostic::new; a later version may add fields. - Diagnostics
- The errors a frontend or validator reported, in the order reported.
- Function
Expression - An expression with a function and no operand.
- Function
Ref - A function reference: its identifier and options.
- Input
Declaration .input {$name …}: binds an external variable, optionally through a function.- Literal
- A literal: its cooked value (escapes processed). Whether it was quoted is not data-model information and is not kept.
- Literal
Expression - An expression whose operand is a literal.
- Local
Declaration .local $name = {…}: binds a local variable to an expression.- Markup
- Markup:
{#name …},{#name … /}or{/name …}. - MsgId
- A message id: which message of a build’s catalogs.
tr!and the generated module make them; an application compares, hashes and passes them, and never builds one from a number. - Options
- The options of a function or markup, in source order.
- Parsed
- The result of parsing one message.
- Pattern
- A pattern: a sequence of parts with no empty
Textand no two adjacentTextparts (Pattern::pushmerges and drops accordingly). - Pattern
Message - A message without selectors: declarations and one pattern.
- Select
Message - A message with a matcher: declarations, selectors and variants.
- Span
- A byte range in the source:
start ≤ end ≤ len, both on char boundaries. - Variable
Expression - An expression whose operand is a variable.
- Variable
Ref - A variable reference, by name (without the
$sigil). - Variant
- A variant: one key per selector, and a pattern.
Enums§
- Declaration
- A declaration.
- Dir
- Text direction.
- Error
Class - The category of an
ErrorKind(spec/errors.md). - Error
Kind - The kind of an MF2 error: the 13 error types of the WG test suite
(
test/README.md, “Error Codes”) plus Unsupported Operation and the umbrella Message Function Error ofspec/errors.md. - Expression
- An expression: an operand with an optional function, or a function alone.
- Key
- A variant key.
- Markup
Kind - The three forms of markup.
- Message
- A message: a single pattern, or a selection among variants.
- Option
Value - An option’s value: a literal or a variable.
- Pattern
Part - One element of a
Pattern.
Traits§
- Frontend
- A parser from MF2 source to the data model.
Functions§
- is_
name_ char name-char = name-start / DIGIT / "-" / ".".- is_
name_ start name-start: an ASCII letter,+,_, or a non-ASCII character that is not whitespace, a bidi control, a surrogate, a private-use character or a noncharacter.- split_
identifier - Splits an identifier at its namespace separator:
"ns:name"→(Some("ns"), "name"),"name"→(None, "name"). A name cannot contain:, so the first colon is the separator.