pest icon indicating copy to clipboard operation
pest copied to clipboard

Please add an example on how to define multiple `Parser` structs in the same crate

Open lucatrv opened this issue 7 years ago • 2 comments

As in subject, I am struggling to understand how to define multiple Parser structs in the same crate, each one relying on its own grammar file.

lucatrv avatar Nov 08 '18 23:11 lucatrv

Due to the fact that the current derive spills the Rule enum into the same namespace, the parsers need to be in different namespaces. However, the following should work:

mod a {
    #[derive(Parser)]
    #[grammar = "a.pest"]
    pub struct Parser;
}
mod b {
    #[derive(Parser)]
    #[grammar = "b.pest"]
    pub struct Parser;
}

You then have a::Parser/a::Rule and b::Parser/b::Rule.

CAD97 avatar Nov 09 '18 04:11 CAD97

This works, thanks for your hint! However if you agree I would keep this issue open, as in my opinion a similar example should be reported in the pest book.

lucatrv avatar Nov 09 '18 23:11 lucatrv