rust-peg
rust-peg copied to clipboard
Bounds on trait objects and impl traits not parsing
The following will not parse:
rule operand() -> Box<dyn Operand + 'input>
The error:
error: expected one of "&", "(", "::", "<", "dyn", "impl"
--> src\parse.rs:41:45
|
41 | rule operand() -> Box<dyn Operand + 'input>
| ^^^^^^
I believe the issue is in the rust_type()
rule of grammar.rustpeg:
rule rust_type()
= BRACKET_GROUP()
/ "&" LIFETIME()? "mut"? rust_type()
/ "dyn" rust_type() ++ "+" // here
/ "impl" rust_type() ++ "+" // and here
/ "(" (rust_type() ++ "," ","?)? ")"
/ ("<" rust_type() ("as" rust_ty_path())? ">")? rust_ty_path()
rust_type()
s shouldn't follow "dyn" and "impl"; instead it should be something that parses type parameter bounds (which include rust types AND lifetimes) (ref) (ref). I think the rules to parse that might already be written as part of rust_where_clause()
and could perhaps be factored out, but I don't have time at the moment to verify that.