package talaria-bibtex

  1. Overview
  2. Docs

Predefined bibtex fields and helper functions.

include Field_types.self
type pages =
  1. | Loc of int
  2. | Interv of int * int
type name = {
  1. lastname : string;
  2. firstname : string;
}
type kind =
  1. | Article
  2. | Inproceedings
  3. | Book
  4. | Talk
  5. | Poster
type 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
type ('a, 'b) bijection = {
  1. to_ : 'a -> 'b;
  2. from : 'b -> 'a;
}

Bijection record

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

Bijection inversion

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

Bijection composition

type t

The type of record within the namespace

type 'info field_action

The type of a field getter or updater

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

Aliases for the field types

type 'a field = < x : 'a ; mut : Orec.Type_data.imm ; ret : 'a option > get
type 'a mut_field = < x : 'a ; mut : Orec.Type_data.mut ; ret : 'a option > get
type 'a exn_field = < x : 'a ; mut : Orec.Type_data.imm ; ret : 'a > get
type 'a exn_mut_field = < x : 'a ; mut : Orec.Type_data.mut ; ret : 'a > get
type ('param, 't) update = ('param Orec.Type_data.updater * 't) field_action
val 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.

val 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.

val new_field_mut : unit -> 'ty mut_field
val new_field_exn : unit -> 'ty exn_field
val new_field_exn_mut : unit -> 'ty exn_mut_field
val 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 }

val (^=) : < x : 'ty.. > get -> 'ty -> (_ Orec.Type_data.const, t) update
val 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

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

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

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

Copy a mutable field

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

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

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

getter, updater and setter for t

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

Operator version of get+update and set

val (.%{}) : 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
val (.%{}<-) : t -> < x : 'ty ; mut : Orec.Type_data.mut.. > get -> 'ty -> unit
val 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

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

Operator version of transmute

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

exception based version of transmute

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

Operator version of transmute_exn

type '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

exception Unknown_attribute of string * string

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

val str : 'a named_field -> string field

Create a string view from a named_field

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

Field creation helper

Predefined field kind

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

List of predefined fields

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

The default typed keys when parsing bibtex file

Direct access functions

val get_uid : t -> string

Both uid and kind are compulsory

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

state default to WIP when the field is absent

type entry = t

Type alias

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

Raw database and entries

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

Innovation. Community. Security.