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

atdpy: Add support for partial parsing #344

Open
mjambon opened this issue Jun 27, 2023 · 0 comments
Open

atdpy: Add support for partial parsing #344

mjambon opened this issue Jun 27, 2023 · 0 comments
Labels
feature request Big and small feature requests target:python Issues related to the Python backend (atdpy)

Comments

@mjambon
Copy link
Collaborator

mjambon commented Jun 27, 2023

For atdpy or other code generators, we would like to add the option to skip malformed elements and report them as errors, as it's done by tree-sitter parsers and ocaml-tree-sitter.

Partial parsing is based on removing malformed elements from list and option containers. This results in a well-formed result and a list of malformed JSON nodes rather than failing completely.

Applications

The goal is for a JSON consumer - typically a client reading a response from a server - to make the best of what the server produces. This happens when the server response is a list of items of which some declare a new kind:

type flavor = [
| Vanilla
| Chocolate
| Mango
| Pear (* new! *)
]

type available_flavors = flavor list

The following JSON data is of type available_flavors:

[ "Vanilla", "Pear", "Chocolate" ]

An older client that doesn't know about the latest Pear flavor can't read this list correctly but it can ignore the unknown flavor. The generated from_json function would read the JSON input as if it were

[ "Vanilla", "Chocolate" ]

and would report the node "Pear" as an error where the type available_flavors (older version) was expected.

@mjambon mjambon added feature request Big and small feature requests target:python Issues related to the Python backend (atdpy) labels Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Big and small feature requests target:python Issues related to the Python backend (atdpy)
Projects
None yet
Development

No branches or pull requests

1 participant