Fix some holes in documentation#720
Merged
zesterer merged 7 commits intozesterer:mainfrom Feb 1, 2025
Merged
Conversation
zesterer
reviewed
Jan 26, 2025
src/lib.rs
Outdated
Comment on lines
+2074
to
+2079
| /// let list = letter | ||
| /// .repeated() | ||
| /// .to_slice() | ||
| /// .map(|string: &str| string.chars()) | ||
| /// .into_iter() | ||
| /// .collect_exactly::<[char; 4]>(); |
Owner
There was a problem hiding this comment.
I feel like this is a somewhat contrived example since the code could be expressed equivalently but more simply like so:
let list = letter.repeated().collect_exactly::<[char; 4]>();A better example might be something like:
// Parses whole integers
let num = text::int().padded().map(|x| x.parse::<u64>().unwrap());
// Parses a range like `0..4` into a vector like `[0, 1, 2, 3]`
let range = num.ignore_then(just("..")).then(num)
.map(|(x, y)| x..y)
.into_iter()
.collect::<Vec<_>>();
// Parses a list of numbers into a vector
let list = num.separated_by(just(',')).collect::<Vec<_>>();
let set = range.or(list);
assert_eq!(set.parse("0, 1, 2, 3").unwrap(), [0, 1, 2, 3]);
assert_eq!(set.parse("0..4").unwrap(), [0, 1, 2, 3]);
Contributor
Author
There was a problem hiding this comment.
Oh okay, thank you! I was struggling to think of a useful example lol
Owner
There was a problem hiding this comment.
It's difficult! A lot of chumsky's parsers only become useful at scale, so coming up with short examples that demonstrate their use it tough.
zesterer
requested changes
Jan 26, 2025
Owner
zesterer
left a comment
There was a problem hiding this comment.
Thanks for the PR! I think these changes are great. I've just one suggestion regarding one of the examples.
Owner
|
Thanks for the PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello!
Added some missing documentation, mostly examples and filling in holes in the error module.
Change list:
Let me know if I should make any changes