package popper

  1. Overview
  2. Docs

Types

type 'a t

A value of type 'a t is a parser that when run with an Input.t value, produces some output containing a value of type 'a.

Basic Combinators

val map : ('a -> 'b) -> 'a t -> 'b t

map f s creates a sample that when run maps its output value using the function f.

val return : 'a -> 'a t

return x is a sample that does not read any input and always produces a value containing x.

val bind : 'a t -> ('a -> 'b t) -> 'b t

bind s f is a sample that when run, first executes s on the given input, then applies its output value to f in order to produe a new sample that is run on the remaining input. This is the monadic operator for sequencing sample operations.

val both : 'a t -> 'b t -> ('a * 'b) t

both s1 s2 is a sample that when run executes s1 followed by s2 and combines their result.

val size : int t

size returns the current max-size argument.

val sized : (int -> 'a t) -> 'a t

sized f lifts the function f that depend on a size argument to a sample.

val resize : int -> 'a t -> 'a t

resize n s creates a sample that when run fixes the size parameter to n.

val one_of : 'a t list -> 'a t

one_of ss is a sample that selects on of the given sample from the list ss.

val one_value_of : 'a list -> 'a t

one_vlaue_of xs same as one_of but lifts all values to samples using return.

val choose : (float * 'a t) list -> 'a t

choose fss chooses one sample from the list with a probability corresponding to the relative weight, as specified by the weight and sample pairs in fss.

val delayed : (unit -> 'a t) -> 'a t

delayed f is sample that delays the production of the sample using f until run

val sequence : 'a t list -> 'a list t

sequence ss is a sample that runs each sample in ss and combines their results in a list.

Primitives

val unit : unit t

unit is a sample that produce a unit value without consuming any input.

val int : int t

int is a sample that produces int values.

val int32 : int32 t

int32 is a sample that produces int32 values.

val int64 : int64 t

int64 is a sample that produces int64 values.

val char : char t

char is a sample that produces char values.

val float : float t

float is a sample that produces float values.

val bool : bool t

bool is a sample that produces bool values.

val fn : 'a t -> ('b -> 'a) t

fn s is a sample that produces a function value.

val string : string t

char is a sample that produces char values.

Combinators for higher-kinded types

val option : 'a t -> 'a option t

option s is a sample that either produces a value None or a value of Some using s.

val result : ok:'a t -> error:'b t -> ('a, 'b) result t

result ~ok ~error is a sample that produces a result value, either using the ok sample, or an error using the error sample.

val list : 'a t -> 'a list t

list s is a sample that produces a list using the give s. The size of the list is not determined but is influenced by the implicit size parameter.

Debugging combinators

val log_key_value : string -> string -> unit t

log_key_value key value is a sample that when run logs the given key and value pair without consuming any input.

val with_log : string -> (Format.formatter -> 'a -> unit) -> 'a t -> 'a t

with_log key pp s enhances the given sample s so as to also log its result using the key and printer pp for producing a string value.

val with_consumed : 'a t -> ('a * Consumed.t) t

with_consumed s is a sample produces a pair of a value using s and its consumed data. This would only be used for debugging purposes.

val tag_name : string -> 'a t -> 'a t

tag_name name s is a sample that when run, applies s but tags its consumed input with the given name. Mostly useful for debuggin.

module Syntax : sig ... end
module Int : sig ... end
module Float : sig ... end
module List : sig ... end
module Array : sig ... end
module String : sig ... end
module Tuple : sig ... end
OCaml

Innovation. Community. Security.