cls_json module
- class cls.cls_json.CLSDecoder(**kwargs)[source]
A custom JSON decoder for decoding objects of different types from a JSON string related to Finite Combinatory Logic.
The decoder uses the __type__ field in the JSON string to determine the type of the object being decoded. The object is then constructed using the information in the JSON string.
The decoder supports several different types of objects including Tree, Combinator, Apply, Failed, Arrow, Intersection, Product, Omega, Constructor, Subtypes, InhabitationResult, and FiniteCombinatoryLogic
- combinator_hook(dct)[source]
A hook for processing the combinator field in the JSON string.
By default, the hook simply returns the combinator field without any processing.
- Parameters
dct (dict) – The dictionary representing the JSON object being decoded.
- Returns
The combinator field.
- Return type
dict
- constructor_hook(dct)[source]
Return the input dictionary dct unmodified.
This method is a hook for CLSDecoder class to handle Constructor objects during JSON decoding. It simply returns the input dictionary dct unmodified.
- Parameters
dct (dict) – A dictionary representing a JSON object.
- Returns
The input dictionary dct unmodified.
- Return type
dict
- class cls.cls_json.CLSEncoder(**kwargs)[source]
A custom JSON encoder for classes related to Finite Combinatory Logic.
This class extends json.JSONEncoder and provides a custom implementation of the default method to handle objects of the classes Tree, Combinator, Apply, Failed, Arrow, Intersection, Product, Omega, Constructor, Subtypes, InhabitationResult, and FiniteCombinatoryLogic.
The output of the encoding process is a dictionary with a special key __type__ that indicates the type of the original object. The remaining keys in the dictionary store the attributes of the original object.
- combinator_hook(o)[source]
Handle the encoding of Combinator objects.
This method delegates the encoding of a Combinator object to the default method of json.JSONEncoder.
- Parameters
o (Combinator) – The Combinator object to be encoded.
- Returns
The encoded Combinator object.
- Return type
dict
- constructor_hook(o)[source]
Handle the encoding of Constructor objects.
This method delegates the encoding of a Constructor object to the default method of json.JSONEncoder.
- Parameters
o (Constructor) – The Constructor object to be encoded.
- Returns
The encoded Constructor object.
- Return type
dict
- default(o)[source]
Handle the encoding of objects.
This method provides a custom implementation of the default method to handle objects of various types related to Finite Combinatory Logic. If the object is not one of the supported types, the method delegates the encoding to the default method of json.JSONEncoder.
- Parameters
o (object) – The object to be encoded.
- Returns
The encoded object.
- Return type
dict