Draft
Conversation
5135ac8 to
d86637a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an attempt to demonstrate using
JSON.parsedirectly in MoonBit for json parsing.The new implementation relies on Reviver has context parameter. Engines without this will fail to parse large numbers correctly, losing precision during parsing. The core-js polyfill exist though, but it would not benefit from the size shrink a lot since it would reintroduce a whole parsing mechanism.
The present implementation of MoonBit gives a lot of detailed errors, while the
JSON.parsesimply throwsSyntaxError, with the randomly customized error messages. The new implementation introduces a new suberror case calledSyntaxErrorwhich is for JS backend. It might be possible to addensure(input : StringView) -> Unit raise ParseErrorwhich preserves the MoonBit parsing mechanism for reporting precise errors, and it will be eliminated if not used.The new implementation discovered some test cases where MoonBit and JS behavior diverge, notably on handling some unicode strings, which we will investigate furthur.
This PR can shrink roughly 200 kB