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 dictionary
Creates an opened, empty dictionary.
val tag : name:string ->
?label:Markdown.text ->
descr:Markdown.text ->
?value:'a -> 'a dictionary -> 'a tag
Register 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 -> unit
Same as tag
but to not return the associated tag.
val find : 'a dictionary -> 'a tag -> 'a
Returns the value associated to some tag.
Not_found
if no value is associated to the tag.val lookup : 'a dictionary -> 'a -> 'a tag
Returns the tag associated to a value.
Not_found
if no value is associated to the tag.val find_tag : 'a dictionary -> string -> 'a tag
Returns 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 prefix
Register 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 tag
Returns 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 tag
Publish a new instance in the documentation.
'a dictionary -> Data.Tag.t list
: Obtain all the tags registered in the dictionary so far.
val set_lookup : 'a dictionary -> ('a -> 'a tag) -> unit
Set 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:Package.package ->
name:string ->
descr:Markdown.text ->
'a dictionary -> (module 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.