Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add doc for comments #30

Merged
merged 2 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 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