Crates.io | mf2_parser |
lib.rs | mf2_parser |
version | 0.1.1 |
source | src |
created_at | 2024-10-13 15:23:05.725641 |
updated_at | 2024-10-13 15:29:40.406594 |
description | Parser and AST definitions for MessageFormat 2 |
homepage | |
repository | https://github.com/lucacasonato/mf2-tools |
max_upload_size | |
id | 1407415 |
size | 150,006 |
The mf2_parser
crate provides a parser for the Message Format 2 syntax. It can
parse any sequence of Unicode scalar values (valid UTF-8) into an AST
representing the Message Format 2 syntax. The parser has very strong error
recovery, so it can parse even very broken or incomplete input (like is common
in editors).
Use the mf2_printer
crate to pretty-print the AST back into the human-readable
MessageFormat 2 syntax.
Add this to your Cargo.toml
:
[dependencies]
mf2_parser = "0.1"
Then you can parse a string like this:
use mf2_parser::parse;
let (ast, diagnostics, source_text_info) = parse("Hello, {$name}!");
if !diagnostics.is_empty() {
panic!("Failed to parse message: {:?}", diagnostics);
}
println!("AST: {:?}", ast);
This project is licensed under GPL-3.0-or-later.