1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
peg::parser! { pub grammar foo_parser() for str { use super::types::Foo; pub rule foo() -> Foo = "foo" { Foo } } } mod types { #[derive(PartialEq, Debug)] pub struct Foo; } #[test] fn main() { assert_eq!(foo_parser::foo("foo"), Ok(types::Foo)); }