Skip to content

About

A Rust library for parsing ICU MessageFormat v2 (MF2)

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mf2-parser

A Rust library for parsing ICU MessageFormat v2 (MF2) strings.

Overview

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.

Features

  • 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.

Usage

Add this to your Cargo.toml:

[dependencies]
mf2-parser = "0.1"

Example

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),
}

API

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.

Specification

This library aims to follow the ICU MessageFormat v2 specification as closely as possible. Please report any discrepancies or missing features.

License

MIT

Acknowledgements

Based on the work of the Unicode MessageFormat Working Group and TypeSccript's implementation of MessageFormat v2.

About

A Rust library for parsing ICU MessageFormat v2 (MF2)

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages