Skip to main content

Crate mf2_model

Crate mf2_model 

Source
Expand description

mf2-model — the Unicode MessageFormat 2 (MF2) interchange data model as Rust types, plus the identities and error kinds every Rust MF2 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].

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

The Rust MF2 book is the user guide: how the crates fit together, web and native applications, the command line, and what 2.x promises. 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 None value is the spec’s true (an attribute written without a value).
CatchAllKey
The catch-all key. Its value lets other formats keep an identifier; it is always None from 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.
FunctionExpression
An expression with a function and no operand.
FunctionRef
A function reference: its identifier and options.
InputDeclaration
.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.
LiteralExpression
An expression whose operand is a literal.
LocalDeclaration
.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 Text and no two adjacent Text parts (Pattern::push merges and drops accordingly).
PatternMessage
A message without selectors: declarations and one pattern.
SelectMessage
A message with a matcher: declarations, selectors and variants.
Span
A byte range in the source: start ≤ end ≤ len, both on char boundaries.
VariableExpression
An expression whose operand is a variable.
VariableRef
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.
ErrorClass
The category of an ErrorKind (spec/errors.md).
ErrorKind
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 of spec/errors.md.
Expression
An expression: an operand with an optional function, or a function alone.
Key
A variant key.
MarkupKind
The three forms of markup.
Message
A message: a single pattern, or a selection among variants.
OptionValue
An option’s value: a literal or a variable.
PatternPart
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.