package orsetto
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=e260412b2dd0f98cfe3dc7ed5c31a694eb31c93cd207c51fa12675b790234ee0ad3bf07d9be17a4dc266fedfe55b14c967cad7bc0c9414063eef8afd59f3d0d1
doc/orsetto.cf/Cf_data_ingest/index.html
Module Cf_data_ingest
Ingesting data according to an abstract model.
Overview
This module facilitates the ingestion of data conforming to an abstract model using any interchange language provided with a basis module defining the scanner type and some basic scanners and scanner composers.
Data models are functionally composable. Optional affix convenience operators are provide an indiomatic syntax.
With a fully composed data models and the ingest specialization of an interchange language, you produce a scanner that recognizes well-typed values according to the corresponding model.
A data model represents either the "primitive" type of a scalar value or a "composed" type of a group of values.
A primitive model represents an OCaml value identified by a Cf_type.nym. Some nyms are conventionally accepted by every interchange language in the Orsetto distribution:
Cf_type.UnitA type with exactly one value, e.g. the JSON "null" value.
Cf_type.BoolA boolean value type.
Cf_type.IntAn integer value in the range that an OCaml nt can represent.
Cf_type.Int32An integer value in the range that an OCaml nt32 can represent.
Cf_type.Int64An integer value in the range that an OCaml nt64 can represent.
Cf_type.FloatAn IEEE 754 floating point value in the range that an OCamlfloatcan represent.
Cf_type.StringAn octet string, not necessarily associated with a particular encoding.
Cf_type.OpaqueAn opaque value conventionally representing any scalar or group value in the underlying interchange language. (Note well: opaque values may contain interchange language specific elements that cannot expressed in other interchange languages.)
A group model takes one of the following forms:
- Vector A sequence of zero, one or more elements all of with the same model.
- Table A sequence of zero, one or more pairs, comprising a domain model and a codomain model, where the domain model corresponds to a totally ordered type and no two pairs in the sequence share the same domain value.
- Record A sequence of zero, one or more elements, each of which may have a different model indicated by its position in the sequence.
- Structure A sequence of zero, one or more pairs, comprising an index model and a field model, where the index model corresponds to a totally ordered type, the field model is indicated by the value of the index, and no two pairs in the sequence share the same index value.
- Variant Exactly one pair, comprising an index model and a field mode, where the field model is indicated by the value of the index.
Generalized Data Models
The types and values in this section facilitate the composition of abstract data models for use in constructing scanners with interchange languages for which an ingest specialization is defined.
The type constructor 'v model represents the ingestion of 'v values decoded from some interchange language.
val primitive : 'v Cf_type.nym -> 'v modelUse primitive nym to compose a model that corresponds to all the values of the type associated with nym.
Use cast f m to compose a model that corresponds to the values produced by applying f to the values recognized by scanners for the model m. If applying f raises Not_found, then the scanner recognizes no value. If f raises Failure, then the exception is converted into a Bad_syntax exception from the scanner.
Use defer m to compose a model by forcing m as needed. This is useful for composing recursive data models to be used in the array arguments of the choice and variant model constructors (see below).
Use choice a to compose a model that corresponds to the values produced by the first scanner in the array of scanners corresponding to the models in a.
Use vector m to compose a model that corresponds to a variable length array of values recognized by the scanner for the model m. Use the optional ~a and ~b arguments to constrain the length of the vector to a minimum of a and/or a maximum of b.
class 'key index : ?cmp:('key ->
'key ->
int) -> ?model:'key model -> 'key Cf_type.nym -> object ... endUse new index nym to create an index object for the type indicated by nym required for composing table, structure and variant group models. Use the optional ~cmp argument to specify a concrete comparator function to use instead of Stdlib.( = ). Use the optional ~model argument to specify the model explicitly, otherwise the primitive model for nym is used for the domain or index in the compoed group model.
Use table k v to compose a model that corresponds to a variable length array of pairs comprising a domain value of the type described by the index k and a codomain value of the type described by the model v. Use the optional ~a and ~b arguments to constrain the length of the table to a minimum of a and/or a maximum of b.
The abstract type parameter for group elements where the position in the sequence indicates the model for the element.
The type constructor ['g, 'f, 'v] group represents the composition of a group with fields of disparate model in each element on the sequence. The 'g parameter is either element for record groups or 'k index for the other cases. The 'f parameter indicates the type of the composer function that produces the final value from its component parts. The 'v parameter indicates the type of the value produced.
The type constructor ['g, 'p] bind represents the model of a specific element in a group with fields or elements of disparate type. In the case where type 'g is element, the type 'p corresponds to the type indicated by the position in the sequence. In the case where type 'g is 'k index, the type 'p corresponds to the type indicated by its index value.
val nil : ('g, 'v, 'v) groupThe empty group that comprises the composition of a value.
Use bind b g to prepend the group element b to the group g.
module Element : sig ... endA submodule containing composers for elements indexed by position.
Use record g f to compose a data model for a record consisting of the elements described by g and the composer f, which is applied to the values scanned in the sequence to produce the result.
module Field : sig ... endA submodule containing composers for elements indexed by some totally ordered domain type.
Use structure i g f to compose a data model for a structure consisting of the fields indexed by i as described by g, with the composer f, which is applied to the values scanned in the sequence to produce the result.
Use variant i s to compose a data model for a variant indexed by i with cases described by s. Raises Invalid_argument if more than one pair k, m in s has the same value of k. The model m describes how the field value is scanned in the case where the index value is k.
module Affix : sig ... endA submodule containing affix operators the provide a convenient and idiosyncratic syntax for composing record and structure models.
Specialization
Usage of generalized data models with a specific interchange language entails composing an ingest specialization for it. The types and values in this section are provided for that purpose.
The extensible control type. Facilitates composing data models with features extended by the ingest specialization for unique features of the interchange language. A value of type ('a, 'b) control represents a conversion of a model of type 'a model to a model of type 'b model as a side effect of any additional constraints applied.
A control value Cast f represents the operation of applying f to a scanned value to produce that value admitted by the model.
Use control m c to compose a new model comprising the application of c to the model m.
type 'k pair = [ | `Table of 'k Cf_type.nym| `Structure of 'k Cf_type.nym| `Variant of 'k Cf_type.nym
]Values of type 'k pair are used to describe the structure of pair elements in sequences that comprise group data models indexed by values of type 'k.
Values of type 'k container are used to describe the structure of sequences that comprise group data models.
Values of type occurs describe the optional minimum and maximum number of elements contained by a group data model.
val occurs : ?a:int -> ?b:int -> unit -> occursUse occurs () to construct a value of type occurs with validated content. Use ~a to specify a non-negative minimum number of elements. Use ~b to specify a non-negative maximum number of elements. Raises Invalid_argument if either a or b is negative, or if a > b.
module type Basis = sig ... endDefine a module of type Basis to create an ingest specialization.
module type Profile = sig ... endThe module type of ingest specializations.