A Rust library for parsing ICU MessageFormat v2 (MF2) strings.
rust-mf2-parser is a library crate that provides a parser for the MessageFormat v2 syntax, as defined by the Unicode MessageFormat Working Group. MessageFormat v2 is a next-generation internationalization message syntax designed for robust, locale-aware message formatting.
This library parses MF2 strings into a structured Rust model, enabling further processing, validation, or transformation for localization workflows.
- Full MF2 Syntax Support: Parses declarations, patterns, select messages, variants, expressions, markups, and attributes as described in the MF2 specification.
- Error Reporting: Provides syntax error information for invalid input.
Add this to your Cargo.toml:
[dependencies]
mf2-parser = "0.1"use rust_mf2_parser::parser::Mf2Parser;
let input = "Hello,{ $name :getName }!!"
let mut parser = Mf2Parser::new(input);
let message = parser.parse();
match message {
Ok(ast) => println!("Parsed AST: {:?}", ast),
Err(e) => println!("Parse error: {:?}", e),
}The main entry point is the Mf2Parser struct:
Mf2Parser::new(src: &str) -> Mf2Parser: Creates a new parser instance.Mf2Parser::parse(&mut self) -> Result<Message, SyntaxError>: Parses the input string
and returns the message AST or a syntax error.
This library aims to follow the ICU MessageFormat v2 specification as closely as possible. Please report any discrepancies or missing features.
MIT
Based on the work of the Unicode MessageFormat Working Group and TypeSccript's implementation of MessageFormat v2.