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 #370 with better float EBNF and +inf -NaN +NaN parsing #371

Merged
merged 1 commit into from
Feb 28, 2022

Conversation

juntyr
Copy link
Member

@juntyr juntyr commented Feb 27, 2022

Fixes #370

Fixes the RON grammar for floats to be equivalent to FromStr's grammar (which we use internally):

float = ["+" | "-"], ("inf" | "NaN" | float_num);
float_num = (float_int | float_std | float_frac), [float_exp];
float_int = digit, { digit };
float_std = digit, { digit }, ".", {digit};
float_frac = ".", digit, {digit};
float_exp = ("e" | "E"), ["+" | "-"], digit, {digit};

Consequently, RON now also accepts +inf, -NaN, and +NaN.

In comparison with rustc, FromStr still accepts floats without a leading digit, e.g. .3 - these continue to work. The other way around, rustc accepts underscores in floats while FromStr and all other parsers I checked do not. I've added a special error FloatUnderscore to lint against this case.

  • I've included my change in CHANGELOG.md

@juntyr juntyr self-assigned this Feb 27, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #371 (31a4b68) into master (46aa515) will increase coverage by 0.10%.
The diff coverage is 98.43%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #371      +/-   ##
==========================================
+ Coverage   89.52%   89.63%   +0.10%     
==========================================
  Files          47       48       +1     
  Lines        5157     5219      +62     
==========================================
+ Hits         4617     4678      +61     
- Misses        540      541       +1     
Impacted Files Coverage Δ
src/error.rs 7.89% <0.00%> (-0.11%) ⬇️
src/parse.rs 93.75% <100.00%> (+0.05%) ⬆️
tests/370_float_parsing.rs 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46aa515...31a4b68. Read the comment docs.

@juntyr
Copy link
Member Author

juntyr commented Feb 27, 2022

@kvark @torkleyy I think this should be a simple fix - unless you specifically did not want to accept +inf, -NaN, and +NaN. Explicitly checking for the underscores in floats is of course a bit extra, but might help if someone wanted to copy-paste their Rust struct directly into a RON config.

Copy link
Collaborator

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Love those tests!

@kvark kvark merged commit 4d16313 into ron-rs:master Feb 28, 2022
@juntyr juntyr deleted the 370-float-parsing branch March 1, 2022 07:17
@torkleyy torkleyy mentioned this pull request Jun 6, 2022
2 tasks
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.

Inconsistencies in floating point parsing
3 participants