package opam-format

  1. Overview
  2. Docs
val file : (OpamParserTypes.FullPos.opamfile, OpamTypes.filename * OpamParserTypes.FullPos.opamfile_item list) OpamPp.t
val map_file : (OpamParserTypes.FullPos.opamfile_item list, 'a) OpamPp.t -> (OpamParserTypes.FullPos.opamfile, OpamTypes.filename * 'a) OpamPp.t
val item : (OpamParserTypes.FullPos.opamfile_item, string * OpamParserTypes.FullPos.value) OpamPp.t
val items : (OpamParserTypes.FullPos.opamfile_item list, (string * OpamParserTypes.FullPos.value) list) OpamPp.t
val anonymous_section : ('a, 'b) OpamPp.t -> ((string option * 'a) list, 'b) OpamPp.t

Suitable for the fields sections argument, when the sections are anonymous (section_name = None)

type ('a, 'value) fields_def = (string * ('a, 'value) OpamPp.field_parser) list
val fields : ?name:string -> empty:'a -> ?sections: ('a, (string option * OpamParserTypes.FullPos.opamfile_item list) list) fields_def -> ?mandatory_fields:string list -> ('a, OpamParserTypes.FullPos.value) fields_def -> (OpamParserTypes.FullPos.opamfile_item list, 'a * (string * OpamPp.bad_format) list) OpamPp.t

Parses an item list into a record using a fields_def; errors in a field cause the field to be ignored, and are aggregated into the returned field, bad_format list. Errors are ignored when printing back.

val show_errors : ?name:string -> ?strict:bool -> ?condition:('a -> bool) -> unit -> ('a * (string * OpamPp.bad_format) list, 'a) OpamPp.t

Intended to be piped after fields. If the errors list is non-empty, this raises Bad_format_list if strict, and otherwise prints warnings for all the errors. The errors are then dropped when parsing, and initialised to empty when printing. strict is taken from the global settings if unspecified. condition may be added to only show the errors when it returns true, and only log them otherwise.

val on_errors : ?name:string -> ('a -> (string * OpamPp.bad_format) -> 'a) -> ('a * (string * OpamPp.bad_format) list, 'a) OpamPp.t

Intended to be piped after fields, this processes the given function on the errors, then drops them when parsing. When printing, just sets empty errors.

val partition_fields : ?section:bool -> (string -> bool) -> (OpamParserTypes.FullPos.opamfile_item list, OpamParserTypes.FullPos.opamfile_item list * OpamParserTypes.FullPos.opamfile_item list) OpamPp.t

Partitions items in an opamfile base on a condition on the variable names. If a section is encountered, it is kept in the second list (as filter returning false), unless section is true.

val partition : (OpamParserTypes.FullPos.opamfile_item -> bool) -> (OpamParserTypes.FullPos.opamfile_item list, OpamParserTypes.FullPos.opamfile_item list * OpamParserTypes.FullPos.opamfile_item list) OpamPp.t

Partitions items in an opamfile base on a generic condition on the items

val field : string -> (pos:OpamParserTypes.FullPos.pos -> OpamParserTypes.FullPos.value -> 'a) -> (OpamParserTypes.FullPos.opamfile_item list, 'a option * OpamParserTypes.FullPos.opamfile_item list) OpamPp.t

Parse a single field from a file, return the result and the unchanged item list. The single field is ignored when printing back.

val section : string -> (OpamParserTypes.FullPos.opamfile_item, string option * OpamParserTypes.FullPos.opamfile_item list) OpamPp.t

Parse a single section with the given "kind", towards its name and contents

val extract_field : string -> (OpamParserTypes.FullPos.opamfile_item list, OpamParserTypes.FullPos.value option * OpamParserTypes.FullPos.opamfile_item list) OpamPp.t

Extracts a single item with the given variable name from an item list. The item is removed from the returned item list, and the two are re-combined when printing

val check_opam_version : ?optional:bool -> format_version:OpamTypes.opam_version -> ?f:(OpamTypes.opam_version -> bool) -> unit -> (OpamParserTypes.FullPos.opamfile_item list, OpamParserTypes.FullPos.opamfile_item list) OpamPp.t

Checks the opam_version field; otherwise the identity

val opam_version : ?undefined:bool -> format_version:OpamTypes.opam_version -> unit -> (OpamParserTypes.FullPos.opamfile_item list, OpamParserTypes.FullPos.opamfile_item list) OpamPp.t

Add opam-version field printing at printing, and removes it from parsed fields if undefined (default is false)

Signature handling (wip)

type signature = string * string * string

A signature is a keyid, an algorithm and the signature proper

val signature : (OpamParserTypes.FullPos.value, signature) OpamPp.t
exception Invalid_signature of OpamParserTypes.FullPos.pos * (string * string * string) list option
val signed : check:(signature list -> string -> bool) -> (OpamParserTypes.FullPos.opamfile_item list, signature list * OpamParserTypes.FullPos.opamfile_item list) OpamPp.t

Pp for signed files. Will assert fail if attempting to write a file with an invalid signature.

OCaml

Innovation. Community. Security.