package talaria-bibtex

  1. Overview
  2. Docs

Module Bibtex.FieldsSource

Predefined bibtex fields and helper functions.

include Field_types.self
Sourcetype pages =
  1. | Loc of int
  2. | Interv of int * int
Sourcetype name = {
  1. lastname : string;
  2. firstname : string;
}
Sourcetype kind =
  1. | Article
  2. | Inproceedings
  3. | Book
  4. | Talk
  5. | Poster
Sourcetype state =
  1. | Published
  2. | Accepted
  3. | Submitted
  4. | WIP
    (*

    Publication status

    *)

Talaria-bibtex exposes its own orec namespace

include Orec.Namespace.S
include Orec.Bijection.S
Sourcetype ('a, 'b) bijection = {
  1. to_ : 'a -> 'b;
  2. from : 'b -> 'a;
}

Bijection record

Sourceval flip : ('a, 'b) bijection -> ('b, 'a) bijection

Bijection inversion

Sourceval (%) : ('a, 'b) bijection -> ('c, 'a) bijection -> ('c, 'b) bijection

Bijection composition

Sourcetype t

The type of record within the namespace

Sourcetype 'info field_action

The type of a field getter or updater

Sourcetype 'info get = (('a, 'mut) Orec.Type_data.getter * 'res) field_action constraint 'info = < x : 'a ; mut : 'mut ; ret : 'res >

Aliases for the field types

Sourcetype 'a field = < x : 'a ; mut : Orec.Type_data.imm ; ret : 'a option > get
Sourcetype 'a mut_field = < x : 'a ; mut : Orec.Type_data.mut ; ret : 'a option > get
Sourcetype 'a exn_field = < x : 'a ; mut : Orec.Type_data.imm ; ret : 'a > get
Sourcetype 'a exn_mut_field = < x : 'a ; mut : Orec.Type_data.mut ; ret : 'a > get
Sourcetype ('param, 't) update = ('param Orec.Type_data.updater * 't) field_action
Sourceval empty : t

The empty record

Create a new open record from a list of field updater : create [ field1 ^= value1; field2 ^= value2; ... ] Only const updater make sense in this context, since there is no fields present.

Sourceval new_field : unit -> 'ty field

Creation of a new fields. Note that the type 'ty is weakly polymorphic once the field created. However, in this specific use case, it seems reasonable to annotate the field type by using one of the field type aliases.

Sourceval new_field_mut : unit -> 'ty mut_field
Sourceval new_field_exn : unit -> 'ty exn_field
Sourceval new_field_exn_mut : unit -> 'ty exn_mut_field
Sourceval put : < x : 'ty.. > get -> 'ty -> (_ Orec.Type_data.const, t) update

Constant field updater: record.%{ field ^= v } sets the value of field to v and is equivalent to record.%{ put field v }

Sourceval (^=) : < x : 'ty.. > get -> 'ty -> (_ Orec.Type_data.const, t) update
Sourceval fmap : < x : 'ty.. > get -> ('ty -> 'ty) -> ('a Orec.Type_data.fn, t) update

Field map: record.%{field |= f } or record.%{ fmap field f } are equivalent to record.%{ field ^= f record.%{field} } if the field exists, and do nothing otherwise

Sourceval (|=) : < x : 'ty.. > get -> ('ty -> 'ty) -> ('a Orec.Type_data.fn, t) update

Field combinator orec.%{ x & y } is orec.%{x}.%{y}

Sourceval copy : < x : 'ty ; mut : Orec.Type_data.mut.. > get -> ('a Orec.Type_data.fn, t) update

Copy a mutable field

Sourceval delete : < .. > get -> ('a Orec.Type_data.del, t) update

Delete a field, if the field does not exist, do nothing

Sourceval get : < ret : 'ret.. > get -> t -> 'ret

getter, updater and setter for t

Sourceval update : (Orec.Type_data.any, t) update -> t -> t
Sourceval set : < x : 'ty ; mut : Orec.Type_data.mut.. > get -> 'ty -> t -> unit

Operator version of get+update and set

Sourceval (.%{}) : t -> (_ * 'ret) field_action -> 'ret

(.%{} ) operator:

  • record.%{field} returns the value of the field
  • record.%{field ^= value} returns a functional update of record
  • record.%{field |= f} is equivalent to record.{ field ^= f record.{field} }
  • record.%{delete field} returns an updated version of record without this field
Sourceval (.%{}<-) : t -> < x : 'ty ; mut : Orec.Type_data.mut.. > get -> 'ty -> unit
Sourceval transmute : (< x : 'a ; mut : 'm.. > as 'x) get -> ('a, 'b) bijection -> < x : 'b ; mut : 'm ; ret : 'b option > get

Use the type equality implied by the bijection 'a⟺'b to create a new 'b field getter from an 'a field getter. The new field getter uses option access

Sourceval (@:) : (< x : 'a ; mut : 'm.. > as 'x) get -> ('a, 'b) bijection -> < x : 'b ; mut : 'm ; ret : 'b option > get

Operator version of transmute

Sourceval transmute_exn : (< x : 'a ; mut : 'm.. > as 'x) get -> ('a, 'b) bijection -> < x : 'b ; mut : 'm ; ret : 'b > get

exception based version of transmute

Sourceval (@:!) : (< x : 'a ; mut : 'm.. > as 'x) get -> ('a, 'b) bijection -> < x : 'b ; mut : 'm ; ret : 'b > get

Operator version of transmute_exn

Sourcetype 'a named_field = {
  1. name : string;
  2. f : 'a field;
  3. conv : ('a, string) bijection;
}

A bibtex field consists of an orec field, a name and a translation between the raw text of the field towards a typed field

Sourceexception Unknown_attribute of string * string

The exception Unknown_attribute is raised whenever a type dkey fails to parse its contents to its underlying type.

Sourceval str : 'a named_field -> string field

Create a string view from a named_field

Sourceval named_field : name:string -> ('a, string) bijection -> 'a named_field

Field creation helper

Predefined field kind

Sourceval str_field : name:string -> string named_field
Sourceval int_field : name:string -> int named_field
Sourcemodule StrSet : Set.S with type elt = string
Sourcemodule Database : Map.S with type key = string
Sourceval strset_field : name:string -> StrSet.t named_field

List of predefined fields

Sourceval uid : string named_field
Sourceval title : string named_field
Sourceval authors : name list named_field
Sourceval year : int named_field
Sourceval journal : string named_field
Sourceval booktitle : string named_field
Sourceval volume : int named_field
Sourceval number : int named_field
Sourceval doi : string list named_field
Sourceval arxiv : string named_field
Sourceval abstract : string named_field
Sourceval location : string named_field
Sourceval conference : string named_field
Sourceval raw : string Database.t field
Sourceval default_keys : string field Database.t

The default typed keys when parsing bibtex file

Direct access functions

Sourceval get_uid : t -> string

Both uid and kind are compulsory

Sourceval get_kind : t -> kind
Sourceval get_state : t -> state

state default to WIP when the field is absent

Sourcetype entry = t

Type alias

Sourcetype raw_entry = {
  1. uid : string;
  2. kind : string;
  3. raw : string Database.t;
}

Raw database and entries

Sourceval check : ?with_keys:string field Database.t -> raw_entry Database.t -> data