From c3fb50e4c8fc37af4aaf6cfc14ac4b9d203894c1 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Sun, 29 Jan 2023 09:49:50 +0800 Subject: [PATCH] Add doc for load multiple pest files and `include!` syntax. (#29) * Add doc for load multiple pest files and `include!` syntax. Ref: - https://github.com/pest-parser/pest/pull/759 - https://github.com/pest-parser/pest/pull/758 * Apply suggestions from code review --------- Co-authored-by: Tomas Tauber <2410580+tomtau@users.noreply.github.com> --- src/grammars/grammars.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/grammars/grammars.md b/src/grammars/grammars.md index fbdc23d..f9a291a 100644 --- a/src/grammars/grammars.md +++ b/src/grammars/grammars.md @@ -36,6 +36,22 @@ exists during compilation. However, you can use `Rules` just like any other enum, and you can use `parse(...)` through the [`Pairs`] interface described in the [Parser API chapter](../parser_api.html). +## Load multiple grammars + +If you have multiple grammars, you can load them all at once: + +```rust +use pest::Parser; + +#[derive(Parser)] +#[grammar = "parser/base.pest"] +#[grammar = "parser/grammar.pest"] +struct MyParser; +``` + +Then `pest` will generate a `Rules` enum that contains all the rules from both. +This is useful if you have a base grammar that you want to extend in multiple grammars. + ## Warning about PEGs! Parsing expression grammars look quite similar to other parsing tools you might