Expand description
High performance MessageFormat 2 parser core.
This crate provides the Rust core for parsing Unicode MessageFormat 2.0 messages. It builds a recovering, lossless concrete syntax tree (CST), materialises diagnostics, optionally lowers semantic records, and can encode parse results into the crate’s Binary AST snapshot format.
§Entry points
Use parse_message for a one-shot parse of an in-memory message. Use
parse_source when the caller owns a SourceStore, and
parse_source_session with ParseWorkspace when repeated parsing
should reuse allocations.
§API layers
The crate root re-exports the supported parser, CST, diagnostic, semantic,
source, and workspace types. The snapshot module is the public namespace
for Binary AST snapshot encoding, decoding, and zero-copy views.
§Stability
This crate is pre-1.0. Public APIs are intended to be useful and documented,
but minor releases may still refine names, shape, and snapshot details while
MessageFormat 2 integration work continues. Error code values are exposed so
language bindings can map failures without parsing display strings.
§Example
use ox_mf2_parser::parse_message;
let result = parse_message("Hello, {$name}!");
assert!(result.diagnostics.is_empty());
assert!(result.cst.node_count() > 0);Re-exports§
pub use snapshot::decode_snapshot;pub use snapshot::decode_snapshot_owned;pub use snapshot::parse_batch_result_to_snapshot;pub use snapshot::parse_batch_to_snapshot;pub use snapshot::parse_message_to_snapshot;pub use snapshot::parse_result_to_snapshot;pub use snapshot::parse_session_to_snapshot;pub use snapshot::parse_source_to_snapshot;pub use snapshot::BatchSnapshotResult;pub use snapshot::DecodeError;pub use snapshot::DecodeErrorCode;pub use snapshot::RootId;pub use snapshot::SectionKind;pub use snapshot::SnapshotOptions;pub use snapshot::SnapshotResult;pub use snapshot::SnapshotSourceMetadata;pub use snapshot::SnapshotView;pub use snapshot::SnapshotViewOwned;pub use snapshot::SnapshotWriteError;pub use snapshot::SnapshotWriteErrorCode;
Modules§
- snapshot
- Binary AST snapshot writer, decoder, and accessor.
Structs§
- Batch
Parse Item - Batch
Parse Options - Batch
Parse Result - CstCapacity
- Pre-sizing hint for
CstTables::reserve. - CstChildren
- Iterator over a contiguous edge slice yielding
CstChildvalues. - CstNode
Tokens - Convenience iterator that yields only the token children of a node.
- CstNode
View - Lazy node view: holds the node id + a reference back to the owning view.
- CstTables
- Flat indexed CST tables — the Phase 1 parser’s primary output.
- CstToken
View - Lazy token view.
- CstTrivia
Range - Iterator over a compact trivia range belonging to a token.
- CstTrivia
View - Lazy trivia view.
- CstView
- Lightweight accessor over a parsed
CstTables. - Diagnostic
- Owned public diagnostic.
- Diagnostic
Iter - Diagnostic
Label - Diagnostic
Ref - Lightweight reference-style view over a single diagnostic record.
- Diagnostic
View - Borrowed diagnostics view tied to a
crate::ParseWorkspace. - EdgeId
- Identifier for an edge entry in
crate::CstTables. - NodeId
- Identifier for a node in
crate::CstTables. - Parse
Capacity - Pre-sizing hint passed to
ParseWorkspace::with_capacity. - Parse
Input - Single-source batch input.
- Parse
Options - Parser knobs. See
design/002for the rationale. - Parse
Result - Owned parse result. Detached from any workspace.
- Parse
Session Result - Borrowed parse result. Lives until the next workspace
clear()/reset(). - Parse
Workspace - Reusable workspace for repeated parse, batch parse, benchmarks, and LSP.
- Semantic
Model - Optional semantic lowering result.
- Semantic
View - Borrowed view onto a
SemanticModel. - Source
File - Owned source file registered in
SourceStore. - Source
File Input - Public input used to register a source file with
SourceStore. - Source
Id - Identifier for a source file inside
crate::SourceStore. - Source
Location - Resolved 1-based line/column pair derived from
SourceStore. - Source
Store - Source ownership for single parse, batch parse, diagnostics, and Phase 2 snapshot roots.
- Span
- UTF-8 byte span
[start, end)into the source text. - TokenId
- Identifier for a token record in
crate::CstTables. - Trivia
Id - Identifier for a trivia record in
crate::CstTables.
Enums§
- Batch
Execution - Batch execution mode. Phase 1 only implements
BatchExecution::Sequential; requesting any other mode returns aBatchParseResultwhoseBatchParseResult::executionisSequentialand whoseBatchParseResult::degradedflag is set so callers can observe the fallback. TheParallelvariant is reserved for a future milestone. - Binding
Validation Error Code - Binding input validation failures not better expressed as
TypeError/RangeError. - CstChild
- Reference from an edge to either a node or a token child.
- Diagnostic
Code - Diagnostic code. The catalog is part of the parser’s snapshot compatibility surface — do not reuse a code for a different message.
- Diagnostic
Severity - Severity of a diagnostic. Compact
u8representation; numeric ordering is used by tooling layers but the parser itself does not rely on it. - Initialization
Error Code - Binding runtime initialization failures.
- Message
Mode - Syntactic message mode (
simple-messagevscomplex-message). - OxMf2
Error Domain - Domain classification for a unified API error code.
- Semantic
Message Kind - Data-model message kind (
PatternMessagevsSelectMessage). - Source
Store Error - Errors returned by
SourceStore::try_add. - Source
Text Error Code - Source text access failures after parsing or decoding.
- Syntax
Kind - Shared classification for nodes, tokens, trivia, errors, and missing
productions. Compact
u16representation that is stored directly in node, token, and trivia records.
Constants§
- NONE_
U32 - Sentinel value used for optional table references.
- OX_
MF2_ API_ ERROR_ MIN - Minimum value for ox-mf2 API error codes. Values below this are reserved.
- OX_
MF2_ BINDING_ VALIDATION_ ERROR_ MAX - OX_
MF2_ BINDING_ VALIDATION_ ERROR_ MIN - OX_
MF2_ DECODE_ ERROR_ MAX - OX_
MF2_ DECODE_ ERROR_ MIN - OX_
MF2_ INITIALIZATION_ ERROR_ MAX - OX_
MF2_ INITIALIZATION_ ERROR_ MIN - OX_
MF2_ SNAPSHOT_ WRITE_ ERROR_ MAX - OX_
MF2_ SNAPSHOT_ WRITE_ ERROR_ MIN - OX_
MF2_ SOURCE_ TEXT_ ERROR_ MAX - OX_
MF2_ SOURCE_ TEXT_ ERROR_ MIN
Functions§
- ox_
mf2_ error_ code_ name - Stable programmatic name for an API error code.
- ox_
mf2_ error_ domain - Classify an API error code into its domain.
- parse_
batch - Parse
inputssequentially and return owned results in input order. - parse_
message - One-shot convenience parser. Parses
sourcedirectly and returns an ownedParseResult. The success path does not allocate a temporarySourceStore; malformed inputs build one only when diagnostics need line/column materialisation. - parse_
source - Parse
source_idfromsourcesand return an ownedParseResult. - parse_
source_ session - Reuse
workspaceto parsesource_id. Returns aParseSessionResultborrowed from the workspace.
Type Aliases§
- OxMf2
Error Code - Unified numeric API error code exposed to language bindings.