Expand description
mf2-syntax — MessageFormat 2 syntax for mf2-two: a parser to a lossless
concrete syntax tree with error recovery, lowering to the data model of
mf2_model, the six Data Model Errors, a serializer back to MF2 source,
and the variable analysis the build’s manifest needs.
| Entry point | Gives |
|---|---|
parse_cst / Parser::parse_cst | a lossless Cst (tooling: formatter, diagnostics, editors) |
parse_model / Parser::parse_model / Frontend | the data model plus syntax or data-model diagnostics (what the build uses) |
validate | the Data Model Errors of a model built in code |
serialize | canonical MF2 source for a model |
analyze | external and local variables, markup and functions of a model |
Both parse entry points run one byte-oriented, single-pass, non-recursive
parser writing a flat arena (cst); parse_model keeps no trivia and
lowers the arena to the model. A Parser keeps the arena between calls,
so a pass over many messages allocates it once. A message without {,
}, \ or a leading . (79 % of real messages) takes a fast path: one
scan, and a borrowed single-text model with no allocation.
Diagnostics carry a stable detail code: see code.
#![no_std] + alloc; never linked into the client wasm.
§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 the stand-alone parser, for
tools.
Re-exports§
pub use cst::Cst;pub use cst::CstRef;pub use cst::Node;pub use cst::SyntaxKind;pub use cst::SyntaxNode;
Modules§
- code
- The stable diagnostic codes of
mf2-syntax(mf2_model::Diagnostic::code). - cst
- The concrete syntax tree: a flat, pre-order arena of nodes and tokens.
Structs§
- Analysis
- What
analyzefound. - Name
- A name used by a message: its NFC form (what comparisons and the manifest use) and its spelling as written (first occurrence in source order).
- Parser
- A parser that keeps its arena between calls (the “reused” state of the parser gate): a pass over many messages grows it once.
Enums§
- Error
- A data model that MF2 syntax cannot represent (see
crate::serialize). - Name
Role - Which kind of name was invalid.
Functions§
- analyze
- Analyzes
message. - parse_
cst - Parses
sourceinto a lossless CST (with its syntax diagnostics). - parse_
model - Parses
sourceinto the data model and validates it. - serialize
- Serializes
messageas canonical MF2 source. - validate
- Checks a data model for the six Data Model Errors. Spans are
None.