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

Fix some holes in documentation #720

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

benjamin-cates
Copy link

Hello!

Added some missing documentation, mostly examples and filling in holes in the error module.

Change list:

  • Added examples to error::EmptyError, error::Cheap, error::Simple, Error::Rich
  • Added examples to Parser::into_iter, Parser::to_slice
  • Added note comparing IterParser::Collect and Parser::to_slice on including/excluding ignored patterns.
  • Added links to relevant attribute types in errors
    • It wasn't really clear what error::Rich was storing, especially that the links to RichPattern and RichReason were buried in method headers below, so I thought it would be good to add links to those.
    • It also wasn't clear what the return type of each of the "span" methods was, since they all said they returned "&S", but for some reason, cargo doc linked to https://doc.rust-lang.org/std/primitive.reference.html 😭
  • Fixed inconsistency between docs on Simple::found and Rich::found

Let me know if I should make any changes

Comment on lines +2074 to +2079
/// let list = letter
/// .repeated()
/// .to_slice()
/// .map(|string: &str| string.chars())
/// .into_iter()
/// .collect_exactly::<[char; 4]>();
Copy link
Owner

@zesterer zesterer Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]);

Copy link
Owner

@zesterer zesterer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I think these changes are great. I've just one suggestion regarding one of the examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants