Skip to content

Commit

Permalink
Add doc for load multiple pest files and include! syntax. (#29)
Browse files Browse the repository at this point in the history
* Add doc for load multiple pest files and `include!` syntax.

Ref:

- pest-parser/pest#759
- pest-parser/pest#758

* Apply suggestions from code review

---------

Co-authored-by: Tomas Tauber <[email protected]>
  • Loading branch information
huacnlee and tomtau authored Jan 29, 2023
1 parent db086ce commit c3fb50e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/grammars/grammars.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c3fb50e

Please sign in to comment.