1 unstable release
0.0.0 | Jun 8, 2021 |
---|
#19 in #ion
18KB
389 lines
Pest to Ion
This is a simple tool and library for converting Pest grammars to Ion data format.
The motivation for this is to make a portable way to introspect Pest grammars in other tools as a data format versus having to provide bespoke parsers for the Pest syntax in other platforms.
lib.rs
:
Provides simple conversion from Pest grammar syntax to Amazon Ion.
Example
The easiest way to convert Pest grammars to Ion is from a str
slice:
use pest_ion::*;
use ion_rs::value::*;
use ion_rs::value::reader::*;
fn main() -> PestToIonResult<()> {
// parse a Pest grammar and convert it to Ion element
let actual = r#"a = @{ "a" | "b" ~ "c" }"#.try_pest_to_element()?;
// here is the equivalent Ion element
let ion_text = r#"{
a: {
type: atomic,
expression:
(choice
(string exact "a")
(sequence
(string exact "b")
(string exact "c")
)
)
}
}"#;
let expected = element_reader().read_one(ion_text.as_bytes())?;
// these should be equivalent
assert_eq!(expected, actual);
Ok(())
}
Dependencies
~16MB
~310K SLoC