Skip to main content

Crate mf2_syntax

Crate mf2_syntax 

Source
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 pointGives
parse_cst / Parser::parse_csta lossless Cst (tooling: formatter, diagnostics, editors)
parse_model / Parser::parse_model / Frontendthe data model plus syntax or data-model diagnostics (what the build uses)
validatethe Data Model Errors of a model built in code
serializecanonical MF2 source for a model
analyzeexternal 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 analyze found.
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).
NameRole
Which kind of name was invalid.

Functions§

analyze
Analyzes message.
parse_cst
Parses source into a lossless CST (with its syntax diagnostics).
parse_model
Parses source into the data model and validates it.
serialize
Serializes message as canonical MF2 source.
validate
Checks a data model for the six Data Model Errors. Spans are None.