Skip to content

Commit 14d2279

Browse files
dalanceGeal
authored andcommitted
Fix custom_input_types.md
1 parent 5bf8848 commit 14d2279

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

doc/custom_input_types.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ that can carry line and column information, or to parse
1010

1111
## Implementing a custom type
1212

13-
Let's assume we have an input type we'll call `MyInput`. The goal is to define
14-
nom parsers with this signature: `MyInput -> IResult<MyInput, Output>`.
15-
To employ it in a `named!` parser, you can write it like this:
13+
Let's assume we have an input type we'll call `MyInput`. `MyInput` is a sequence of `MyItem` type.
14+
The goal is to define nom parsers with this signature: `MyInput -> IResult<MyInput, Output>`.
1615

1716
```rust
18-
named!(parser<MyInput, Output>, tag!("test"));
17+
fn parser(i: MyInput) -> IResult<MyInput, Output> {
18+
tag("test")(i)
19+
}
1920
```
2021

21-
Here are the traits we have to implement:
22-
22+
Here are the traits we have to implement for `MyInput`:
2323

2424
| trait | usage |
2525
|---|---|
2626
| [AsBytes](https://docs.rs/nom/latest/nom/trait.AsBytes.html) | casts the input type to a byte slice |
27-
| [AsChar](https://docs.rs/nom/latest/nom/trait.AsChar.html) | transforms common types to a char for basic token parsing |
2827
| [Compare](https://docs.rs/nom/latest/nom/trait.Compare.html) | character comparison operations |
2928
| [ExtendInto](https://docs.rs/nom/latest/nom/trait.ExtendInto.html) |abstracts something which can extend an Extend |
3029
| [FindSubstring](https://docs.rs/nom/latest/nom/trait.FindSubstring.html) | look for a substring in self |
@@ -36,3 +35,9 @@ Here are the traits we have to implement:
3635
| [Offset](https://docs.rs/nom/latest/nom/trait.Offset.html) | calculate the offset between slices |
3736
| [ParseTo](https://docs.rs/nom/latest/nom/trait.ParseTo.html) | used to integrate `&str`'s parse() method |
3837
| [Slice](https://docs.rs/nom/latest/nom/trait.Slice.html) | slicing operations using ranges |
38+
39+
Here are the traits we have to implement for `MyItem`:
40+
41+
| trait | usage |
42+
|---|---|
43+
| [AsChar](https://docs.rs/nom/latest/nom/trait.AsChar.html) | transforms common types to a char for basic token parsing |

0 commit comments

Comments
 (0)