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

Error recovery: ignore malformed elements #334

Open
mjambon opened this issue Mar 14, 2023 · 0 comments
Open

Error recovery: ignore malformed elements #334

mjambon opened this issue Mar 14, 2023 · 0 comments
Labels
enhancement target:biniou Issues related to biniou target:bucklescript Issues related to the Bucklescript backend target:go Issue related to Go/Golang target:java Issues related to the Java backend (atdj) target:json Issues related to all JSON backends target:ocaml Issues related to the OCaml backend (atdgen) target:python Issues related to the Python backend (atdpy) target:scala Issues related to the Scala backend (atds) target:typescript Issues related to the TypeScript backend (atdts)

Comments

@mjambon
Copy link
Collaborator

mjambon commented Mar 14, 2023

Goal: maximize backward compatibility of outdated JSON readers

This was inspired by what tree-sitter parsers do. Tree-sitter is a parser generator. When a tree-sitter parser encounters an unsupported syntax in an input file, instead of failing completely, it will try to contain the error by creating an error node that a client can happily ignore.

We could apply a similar strategy to JSON readers, to any target language: if an ignorable node is malformed, skip it. The ignored material could be reported as an error outside of the main result e.g. an OCaml signature for a JSON reader could be

type error = {
  expected_type: string;
  actual_data: json;
}

(* Interpret JSON data as a 'foo', raising an exception if malformed elements can't be ignored.
   Malformed JSON elements that can be ignored are collected as the error list. *)
val read_foo : json -> foo * error list

Ignorable nodes include list or array elements (ATD list) and optional values (ATD option, nullable).

Tasks:

@mjambon mjambon added enhancement target:bucklescript Issues related to the Bucklescript backend target:python Issues related to the Python backend (atdpy) target:ocaml Issues related to the OCaml backend (atdgen) target:java Issues related to the Java backend (atdj) target:scala Issues related to the Scala backend (atds) target:json Issues related to all JSON backends target:biniou Issues related to biniou target:typescript Issues related to the TypeScript backend (atdts) target:go Issue related to Go/Golang labels Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement target:biniou Issues related to biniou target:bucklescript Issues related to the Bucklescript backend target:go Issue related to Go/Golang target:java Issues related to the Java backend (atdj) target:json Issues related to all JSON backends target:ocaml Issues related to the OCaml backend (atdgen) target:python Issues related to the Python backend (atdpy) target:scala Issues related to the Scala backend (atds) target:typescript Issues related to the TypeScript backend (atdts)
Projects
None yet
Development

No branches or pull requests

1 participant