@@ -10,21 +10,20 @@ that can carry line and column information, or to parse
10
10
11
11
## Implementing a custom type
12
12
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> ` .
16
15
17
16
``` rust
18
- named! (parser <MyInput , Output >, tag! (" test" ));
17
+ fn parser (i : MyInput ) -> IResult <MyInput , Output > {
18
+ tag (" test" )(i )
19
+ }
19
20
```
20
21
21
- Here are the traits we have to implement:
22
-
22
+ Here are the traits we have to implement for ` MyInput ` :
23
23
24
24
| trait | usage |
25
25
| ---| ---|
26
26
| [ 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 |
28
27
| [ Compare] ( https://docs.rs/nom/latest/nom/trait.Compare.html ) | character comparison operations |
29
28
| [ ExtendInto] ( https://docs.rs/nom/latest/nom/trait.ExtendInto.html ) | abstracts something which can extend an Extend |
30
29
| [ 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:
36
35
| [ Offset] ( https://docs.rs/nom/latest/nom/trait.Offset.html ) | calculate the offset between slices |
37
36
| [ ParseTo] ( https://docs.rs/nom/latest/nom/trait.ParseTo.html ) | used to integrate ` &str ` 's parse() method |
38
37
| [ 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