Skip to content

Conversation

sirosen
Copy link

@sirosen sirosen commented May 19, 2025

First off, thanks for maintaining this library!
I'm trying to pitch in a bit to help and make sure things stay healthy.
It's my first time working with Cython, so I'll be a little slow to make changes.


This PR swaps the fast_double_parser for fast_float, per the deprecation warning cited in #83.
It all works cleanly except for a small number of tests regarding scientific notation.

I could use some input on how to push this over the finish line.
None of the fast_float behaviors matches what the JSON5 tests expect, and the one which is labeled json_or_infnan seems like the best fit for the spec in spirit.

Right now, I'm seeing pyjson5.loads(1e2.3) return 100, which is definitely wrong.
But I haven't yet figured out where the issue is. I would guess (from the above) that somehow it's truncating the data to 1e2.

sirosen added 2 commits May 18, 2025 23:52
The only oddity in here is handling around `std::errc` because `0` is
not part of the named enum values. As a workaround, treat the enum
type as an int, and explicitly cast it when comparing it against `0`.
This more accurately matches the supported types for the JSON5 spec.
@Kijewski
Copy link
Owner

Thank you very much for working on that! I'll try to have a look in the next few days.

(I wonder why the CI did not run for you PR, I'll have to investigate that.)

`fast_float` allows for exponents containing floats, which are not
allowed per the JSON5 spec.

Constraining `fast_float` to a format which does not allow for these
exponents results in other supported usages being rejected.

To handle this, explicitly check by adding a new guard.
`has_invalid_exponent` is a string scan which returns true if it finds
a suffix on the string which looks like an invalid exponent.
@sirosen
Copy link
Author

sirosen commented May 19, 2025

I was able to confirm that the string "1e2.3", when passed to fast_float, parses "successfully" as 100.0.
I couldn't find a way to get it working using clever fast_float usage, but once I satisfied myself that it wasn't possible, I added a manual little function to guard against weird invalid exponents (any non-digit char after the sign).

I think it's now in good shape -- all tests pass -- and I hopefully have some more contributions to follow!

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