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

[WIP] Add parsing of lexical numbers #462

Merged
merged 8 commits into from
Jun 28, 2023

Conversation

Zij-IT
Copy link
Contributor

@Zij-IT Zij-IT commented Jun 27, 2023

I figured I would submit a WIP pull request to get your opinion on it, before I spend time writing documentation (as well all know that takes forever), and make any changes that you feel are necessary.

This pull request adds the following public elements:

  • Number - Parses a number given a specific format provided by the lexical crate.
  • number - Which is just the constructor function.
  • format - A reexport of lexical::format

This pull request changes the the following:

  • Relaxes the bound on InputRef::skip_bytes to allow for number to work with SliceInput. I am admittedly not sure if this is the right call, but it seemed like the previous bound was unnecessarily strict.

Questions:

  • Does this look like the API that you would be expecting for a parser like this?
  • Are there any surprises that I should be aware of that force Number to require I: StrInput?
  • Is there any reason for skip_bytes to require StrInput that I should be aware of?
  • Should the aforementioned bound be set-back to StrInput?.

@Zij-IT
Copy link
Contributor Author

Zij-IT commented Jun 27, 2023

Ah forgot to tag the issue. #398

src/input.rs Outdated
Comment on lines 1140 to 1141
#[cfg(feature = "regex")]
#[cfg(feature = "lexical-numbers")]
Copy link
Owner

Choose a reason for hiding this comment

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

I think cfg(any(feature = "regex", feature = "lexical-numbers")) is the proper thing to do here.

src/number.rs Outdated
mod rust {
use super::*;

const FLOAT: Number<RUST_LITERAL, &str, extra::Default, f64> = number();
Copy link
Owner

Choose a reason for hiding this comment

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

It's a bit of a shame that we end up needing to specify the type parameters like number::<RUST_LITERAL, _, _, _>() each time due to the const generic, but by the looks of things there might not be a way around this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but I have no clue how we could even try to work around this, because parse_partial uses the RUST_LITERAL generically.

Unrelated, but It may also be worth it to use const_assert to make sure that the literal provided is valid.

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.

This seems reasonable. That said, it might be worth putting behind an unstable feature flag too for now (with lexical-numbers = ["lexical", "unstable"]). There's enough weirdness with the design (not your fault, just a product of lexical's API) that it would be nice to change this in breaking ways post-release.

@Zij-IT
Copy link
Contributor Author

Zij-IT commented Jun 28, 2023

@zesterer Should be merge-ready :)

@zesterer
Copy link
Owner

Thanks!

@zesterer zesterer merged commit ce9220a into zesterer:main Jun 28, 2023
4 checks passed
@Zij-IT Zij-IT deleted the feature/lexical-numbers branch June 28, 2023 15:13
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