rust-bakery / nom

Rust parser combinator framework
MIT License
9.18k stars 792 forks source link

Make is_a example more obvious #1663

Closed smheidrich closed 1 year ago

smheidrich commented 1 year ago

In the "Choosing a combinator" guide, the example for is_a is to run is_a("ab") on ababc, returning Ok("c", "abab"). The example by itself (without the accompanying explanation) leaves ambiguous whether the reason is_a produced that output was because it parsed ab twice (wrong - that's what tag is for) or because it parsed a or b 4 times (correct). IMHO it would be better if, at least for simple functions like that, it was immediately obvious from the examples alone what they do, or at least for the examples to dispel any confusion remaining after reading the explanations. In this case that can be accomplished by just using abbac as the example string instead, which this MR does.

Geal commented 1 year ago

good idea yes, the examples should be more obvious