Repository navigation
Add a JSON parser example - #185
Merged
Merged
Conversation
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.
Adds
examples/json.rue, a JSON parser and serializer written in Rue, and links it from the README.kindfield, so aJsonvalue can be narrowed withis.\uXXXXwith surrogate pairs (encoded as UTF-8). It also enforces JSON's rules on whitespace, leading zeros and control characters, and callsraisewith a message when the input is malformed.stringifywrites the value back as compact JSON, andgetlooks up keys in objects.Rue string literals have no escape sequences, so the tests write JSON with single quotes and a
json()helper swaps them for double quotes.I also ran 13 malformed inputs through temporary tests (not committed), and each one failed with the expected error.
Note
Low Risk
Documentation and example-only changes with snapshot YAML; no compiler, stdlib, or production puzzle logic is modified.
Overview
Adds
examples/json.rue, a Rue example that parses JSON into tagged structs, serializes back to compact JSON, and exposesgetfor object lookup.mainround-trips a string viastringify(parse(input)).Parsing covers objects, arrays, literals, integer-only numbers (rejects
./e), escapes including\uand surrogate pairs (UTF-8), whitespace rules, andraiseon malformed input. Tests use ajson()helper (single quotes → double quotes) because Rue literals lack escapes.Also adds the usual
examples/json.yamlcompile/test snapshot and links the example in the README.Reviewed by Cursor Bugbot for commit c26de19. Bugbot is set up for automated code reviews on this repo. Configure here.