I'm trying to implement a procedural macro that requires the opening of a grammar file as such:
#[derive(Parser)]
#[grammar = "grammar.pest"]
struct MyParser;
There are two problems with this approach:
- running Cargo in any subfolders of the project makes finding the grammar file hard
- modifying the grammar file does not notify Cargo that it needs to rebuild the project
My current solutions to these problems are quite hacky. In order to have proper control of the project structure, I could require Cargo as a dependency, but this would make the macro painfully slow to compile. I'm not aware if there is any minimum Cargo API crate in the wild. The other problem is solvable by storing the file as a string in an unused constant const _PEST_GRAMMAR: &'static str = include_str!("grammar.pest");
. Not a perfect solution, but definitely doable.
Any fresh ideas on the issues are more than welcome.