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

[Feature Request] Support JSON Numbers #17

Open
Alexhuszagh opened this issue May 12, 2021 · 5 comments
Open

[Feature Request] Support JSON Numbers #17

Alexhuszagh opened this issue May 12, 2021 · 5 comments

Comments

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented May 12, 2021

One of the major motivations for lexical-core's recent developments has been support for parsing floats of different formats, most notably JSON numbers.

A few notable differences exist in comparison to Rust floats, or those in other languages. For example, with rust literals and rust strings. Providing a function of the signature fn parse_tokenized(integral: &[u8], fractional: &[u8], exponent: i32, negative: bool); would therefore allow users to validate their own float formats, while then letting fast-float-rust do the majority of the heavy lifting. It would also not accept special floats.

This should require minimal changes in the parsing implementation, while making the library much more suitable for general-purpose applications.

"NaN"       // valid
"nan"       // invalid
"1.23"      // valid
"1.23e"     // invalid
"1."        // valid
".1"        // valid
"1.23e5"    // valid
"+1.23e5"   // valid
"-1.23e5"   // valid

Meanwhile, in JSON, we get the following:

"NaN"       // invalid
"nan"       // invalid
"1.23"      // valid
"1.23e"     // invalid
"1."        // invalid
".1"        // invalid
"1.23e5"    // valid
"+1.23e5"   // invalid
"-1.23e5"   // valid

This can extend to various markup languages, like TOML, YAML (which has the same rules as JSON), XML, and others.

@lemire
Copy link
Contributor

lemire commented May 12, 2021

Is -1.23e5 ever invalid?

@Alexhuszagh
Copy link
Contributor Author

Alexhuszagh commented May 13, 2021

@lemire Thanks for catching my typo....

@aldanor
Copy link
Owner

aldanor commented May 15, 2021

@Alexhuszagh This makes sense, agreed. However: if we're planning to try and integrate this crate into core/std (in which case this crate would become redundant), what would happen to extra functionality like this?

Just thinking - ideally, this kind of stuff should be provided in std as well? (e.g., "f64::from_parts(...)").

@Alexhuszagh
Copy link
Contributor Author

Alexhuszagh commented May 15, 2021

@aldanor It would be removed from the Rust version, unless we have an RFC to add it. I can proposed a pre-RFC for this, however, on Rust-internals now.

I'm also doing the commits for this right now (it's very rudimentary, but it separates the functionality. The other advantage this has is it would provide easy integration into serde-json, which currently uses a fork of my library, lexical. Code gets faster, I get to pass on some experience I have on features that are crucial for some applications. Everyone wins.

It would also provide a great raison-d'être for this library until the RFC is approved.

@Alexhuszagh
Copy link
Contributor Author

I've added a pre-RFC for this on Rust internals.

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

No branches or pull requests

3 participants