Skip to main content

Crate ox_mf2_parser

Crate ox_mf2_parser 

Source
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;
pub use snapshot::SourceTextUnavailable;

Modules§

snapshot
Binary AST snapshot writer, decoder, and accessor.

Structs§

BatchParseItem
BatchParseOptions
BatchParseResult
CstCapacity
Pre-sizing hint for CstTables::reserve.
CstChildren
Iterator over a contiguous edge slice yielding CstChild values.
CstNodeTokens
Convenience iterator that yields only the token children of a node.
CstNodeView
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.
CstTokenView
Lazy token view.
CstTriviaRange
Iterator over a compact trivia range belonging to a token.
CstTriviaView
Lazy trivia view.
CstView
Lightweight accessor over a parsed CstTables.
Diagnostic
Owned public diagnostic.
DiagnosticIter
DiagnosticLabel
DiagnosticRef
Lightweight reference-style view over a single diagnostic record.
DiagnosticView
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.
ParseCapacity
Pre-sizing hint passed to ParseWorkspace::with_capacity.
ParseInput
Single-source batch input.
ParseOptions
Parser knobs. See design/002 for the rationale.
ParseResult
Owned parse result. Detached from any workspace.
ParseSessionResult
Borrowed parse result. Lives until the next workspace clear() / reset().
ParseWorkspace
Reusable workspace for repeated parse, batch parse, benchmarks, and LSP.
SemanticModel
Optional semantic lowering result.
SemanticView
Borrowed view onto a SemanticModel.
SourceFile
Owned source file registered in SourceStore.
SourceFileInput
Public input used to register a source file with SourceStore.
SourceId
Identifier for a source file inside crate::SourceStore.
SourceLocation
Resolved 1-based line/column pair derived from SourceStore.
SourceStore
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.
TriviaId
Identifier for a trivia record in crate::CstTables.

Enums§

BatchExecution
Batch execution mode. Phase 1 only implements BatchExecution::Sequential; requesting any other mode returns a BatchParseResult whose BatchParseResult::execution is Sequential and whose BatchParseResult::degraded flag is set so callers can observe the fallback. The Parallel variant is reserved for a future milestone.
BindingValidationErrorCode
Binding input validation failures not better expressed as TypeError / RangeError.
CstChild
Reference from an edge to either a node or a token child.
DiagnosticCode
Diagnostic code. The catalog is part of the parser’s snapshot compatibility surface — do not reuse a code for a different message.
DiagnosticSeverity
Severity of a diagnostic. Compact u8 representation; numeric ordering is used by tooling layers but the parser itself does not rely on it.
InitializationErrorCode
Binding runtime initialization failures.
MessageMode
Syntactic message mode (simple-message vs complex-message).
OxMf2ErrorDomain
Domain classification for a unified API error code.
SemanticMessageKind
Data-model message kind (PatternMessage vs SelectMessage).
SourceStoreError
Errors returned by SourceStore::try_add.
SourceTextErrorCode
Source text access failures after parsing or decoding.
SyntaxKind
Shared classification for nodes, tokens, trivia, errors, and missing productions. Compact u16 representation 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 inputs sequentially and return owned results in input order.
parse_message
One-shot convenience parser. Parses source directly and returns an owned ParseResult. The success path does not allocate a temporary SourceStore; malformed inputs build one only when diagnostics need line/column materialisation.
parse_source
Parse source_id from sources and return an owned ParseResult.
parse_source_session
Reuse workspace to parse source_id. Returns a ParseSessionResult borrowed from the workspace.

Type Aliases§

OxMf2ErrorCode
Unified numeric API error code exposed to language bindings.