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

Create conditions from a JSON structure #22

Open
sylvainhalle opened this issue Mar 30, 2021 · 0 comments
Open

Create conditions from a JSON structure #22

sylvainhalle opened this issue Mar 30, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@sylvainhalle
Copy link
Contributor

Add a layer to the library where a complex condition can be constructed by traversing a JSON element with a predefined structure. For example, in the following snippet, reading the top-level element would trigger the instantiation of a ForAll function, with the parameters provided in the contents field.

{
  "name" : "ForAll",
  "contents" : {
    "variable" : "$x",
    "selector" : { ... },
    "condition" : { ... }
  }
}

Since a function can itself use other functions, this traversal and the corresponding construction of objects must be recursive.

Structural modifications

  1. Add a new class called Deserializer, which implements a method deserialize(j) that accepts a JSON structure j and produces a Function object.
  2. Add to all descendants of Function a static method deserialize(d, j), where d is a deserializer and j is a JSON structure.

The task of Deserializer.deserialize(j) is to check the JSON structure, determine what function class C it corresponds to, and call C.deserialize(this, j) to obtain an instance of that class.

The task of C.deserialize(d, j) is to read the JSON structure and create an appropriate instance of the class by reading the fields. If one of these fields is itself a JSON structure j' defining a function, the class can call d.deserialize(j') to obtain that object recursively.

JSON structure

The JSON structure for each function is an object with two mandatory fields:

  • name: a string that contains the name of the class. Deserializer uses this field to dispatch the call to deserialize(this, j) to the proper static class method
  • contents: an object that contains any fields that class needs to instantiate an object; this is the part of the JSON that is sent to a class' deserialize static method. What these fields are is specific to each function. For example, Addition requires an arity to be instantiated, so one of the fields inside contents could be arity associated to a number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants