Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 beginning with exactly three slashes `///`.
And `//!` for document the entire of 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