module Enum:sig..end
Enum factory.
You shall start by declaring a dictionary with Enum.dictionary for your
values. Then, populate the dictionary with Enum.tag values. Finally, you
shall call Enum.publish to obtain a new data module for your type.
You have two options for computing tags: either you provide values when
declaring tags, and these tags will be associated to registered values for
both directions; alternatively you might provide a ~tag function to
Enum.publish.
The difficulty when providing values only at tag definition is to ensure that all possible value has been registered.
The conversion values from and to json may fail when no value has been registered with tags.
type 'a dictionary
type 'a tag
type 'a prefix
val tag_name : 'a tag -> string
val dictionary : unit -> 'a dictionaryCreates an opened, empty dictionary.
val tag : name:string ->
?label:Markdown.text ->
descr:Markdown.text ->
?value:'a -> 'a dictionary -> 'a tagRegister a new tag in the dictionary.
The default label is the capitalized name.
The provided value, if any, will be used for decoding json tags.
If would be used also for encoding values to json tags if no ~tag
function is provided when publishing the dictionary.
Registered values must be hashable with Hashtbl.hash function.
You may register a new tag after the dictionary has been published.
val add : name:string ->
?label:Markdown.text ->
descr:Markdown.text -> ?value:'a -> 'a dictionary -> unitSame as tag but to not return the associated tag.
val find : 'a dictionary -> 'a tag -> 'aReturns the value associated to some tag.
Not_found if no value is associated to the tag.val lookup : 'a dictionary -> 'a -> 'a tagReturns the tag associated to a value.
Not_found if no value is associated to the tag.val find_tag : 'a dictionary -> string -> 'a tagReturns the tag from its name.
Not_found if no tag has been registered with this name.val prefix : name:string ->
?var:string ->
?label:Markdown.text ->
descr:Markdown.text ->
'a dictionary -> 'a prefixRegister a new prefix tag in the dictionary.
The default label is the capitalized prefix.
To decoding from json is provided to prefix tags.
Encoding is done by emitting tags with form 'prefix:*'.
The variable part of the prefix is documented as 'prefix:xxx'
when ~var:"xxx" is provided.
You may register a new prefix-tag after the dictionary has been published.
val instance : 'a prefix -> string -> 'a tagReturns the tag for a value associated with the given prefix.
val extends : name:string ->
?label:Markdown.text ->
descr:Markdown.text ->
?value:'a -> 'a prefix -> 'a tagPublish a new instance in the documentation.
: 'a dictionary -> Server.Data.Tag.t listObtain all the tags registered in the dictionary so far.
val set_lookup : 'a dictionary -> ('a -> 'a tag) -> unitSet tagging function for values. If the lookup function raises `Not_found`, the dictionary will use the tag associated with the provided value, if any.
val publish : package:Server.Package.package ->
name:string ->
descr:Markdown.text ->
'a dictionary -> (module Server.Data.S with type t = 'a)Publish the dictionary. No more tag nor prefix can be added afterwards.
If no ~tag function is provided, the values registered with tags are used.