peg::parser!(grammar p() for str {
rule x() = "x"
pub rule foo() = "-" x() / x()
pub rule bar() = precedence! {
"-" @ {}
--
x() {}
}
});
fn main() {
assert_eq!(p::foo("-x"), Ok(()));
assert_eq!(p::bar("-x"), Ok(()));
assert!(p::foo("--x").is_err());
assert!(p::bar("--x").is_err()); // failed!
}
Sometimes it is necessary to not associative infix, prefix, and postfix operators,
But the precedence! cannot express this situation