mjambon/atdgen — pull request #25 by dsheets (2014-11-04 11:51:28+00:00)
Title: json sum constructors as sibling record fields

This patch adds support for a new annotation, ``, on record fields with sum types which indicates another field in the same JSON object to use as a sum constructor for this field.

This functionality requires mjambon/yojson#11 in order to defer parsing the sum's payload JSON string until the sum's constructor has been read.

Binding a record's constructor tag field is not required. This case is called "implicit" in this patch set and a special field name prefixed with `0jic_` is used to denote these fields and keep them separate from normal OCaml record fields (`0` is not a valid indentifier start character).

The constructor field itself may be anything that serializes to a string and constructor name comparison is done via strings. This means that the constructor field type may be a polymorphic variant and the ``s of the constructors will be used for type-directed parsing of the constructor's payload. Nullary constructors may have their payload field omitted. Multiple payload fields may key on the same constructor field. Default tag and payload types are supported but optional tag and payload types are not.

I would like to proceed as follows:

1. Discussion of the semantics and nomenclature of this feature (I don't really like `constr`.).
2. Discussion of the various error conditions that can arise at run-time and how they should be handled.
3. Discussion of this specific implementation of this feature.

If a future revision of this patchset is merged, I would be happy to write the documentation for this feature. This functionality is required for upcoming [Events API](https://developer.github.com/v3/activity/events/types/) support in [avsm/ocaml-github](https://github.com/avsm/ocaml-github).

Thanks for your time reviewing this work. :-)