Skip to content

Commit

Permalink
Add doc for comments (#30)
Browse files Browse the repository at this point in the history
* Add doc for comments

* Update src/grammars/comments.md

---------

Co-authored-by: Tomas Tauber <[email protected]>
  • Loading branch information
huacnlee and tomtau authored Jan 29, 2023
1 parent 3df8a74 commit db086ce
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Grammars](grammars/grammars.md)
- [Parsing expression grammars](grammars/peg.md)
- [Syntax of pest parsers](grammars/syntax.md)
- [Comments](grammars/comments.md)
- [Built-in rules](grammars/built-ins.md)
- [Example: JSON](examples/json.md)
- [Example: The J language](examples/jlang.md)
Expand Down
40 changes: 40 additions & 0 deletions src/grammars/comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Comments

### Non-doc comments

Comments follow the general Rust style of line (`//`) and block (`/* ... */`) comment forms.
Non-doc comments are interpreted as a form of whitespace.

```pest
/*
Block comment
*/
another_rule = { // line comment
... // whitespace goes anywhere
}
```

### Doc comments

Line doc comments begin with exactly three slashes `///`
and `//!` is used to document the entire grammar file.

```pest
//! A parser for JSON file.
json = { ... }
/// Matches object, e.g.: `{ "foo": "bar" }`
object = { ... }
```

Then will get

```rust
/// A parser for JSON file.
enum Rule {
json,
/// Matches object, e.g.: `{ "foo": "bar" }`
object,
}
```
2 changes: 2 additions & 0 deletions src/grammars/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
`pest` grammars are lists of rules. Rules are defined like this:

```pest
//! Grammar doc
my_rule = { ... }
/// Rule doc
another_rule = { // comments are preceded by two slashes
... // whitespace goes anywhere
}
Expand Down

0 comments on commit db086ce

Please sign in to comment.