Module Kwvalid

module Kwvalid: sig .. end

Validators

This module provides "objects" that validate strings. A given validator essentially imposes a type upon strings, and accepts or rejects them accordingly; they also carry a text description of the type, which can be used in help and error messages.



Types and Exceptions


type t = {
   t : string; (*
description of what this validator considers valid (a noun)
*)
   f : string -> bool; (*
test function
*)
}
The type of validators.
exception Invalid of string * string
Exception rasied by Kwvalid.mustbe and Kwvalid.asserted.

str is an invalid what.

val error : Format.formatter -> string -> string -> unit
val string_of_exn : exn -> string
string_of_exn: convert Kwvalid exceptions to strings describing them.

Calling Validators

Validators are Boolean functions; you can call t.f directly, or use one of these convenience functions.

val valid : t -> string -> bool
valid t str: is str a valid t?
t : the validator
str : the string to be validated
val mustbe : t -> string -> unit
mustbe t str: check that str is a valid t and raise an exception if not.
Raises Invalid if str not a valid t
t : the validator
str : the string to be validated
val asserted : t -> string -> string
asserted t str: check that str is a valid t, raising an exception if not, and return str.
Raises Invalid if str not a valid t
t : the validator
str : the string to be validated

Creating Validators and Primitive Validators


val make : string -> (string -> bool) -> t
make text predicate: make a validator from an arbitrary predicate
val always : t
always considers any argument string valid.
val any : t
any considers any argument string valid.
val never : t
never never considers any argument string valid.
val enum : string list -> t
enum list: considers valid any string in the given list.
module Combinator: sig .. end

Validators


module Number: 
functor (N : NUMBER) -> sig .. end
Number Validators
module Num: sig .. end
Validators for Predefined Number Domains
module String: sig .. end
String Validators
module B: sig .. end
Boolean Validators 𝔹
module File: sig .. end
File Validators
module Directory: sig .. end
Directory Validators
module Json: sig .. end
Json Validators

Combinators for validators


val warning : Format.formatter -> t -> t
warning v: convert the validator v into one that always succeeds, but generates a warning on the formatter fmt if the validation fails.
fmt : the formatter
v : the validator
val not : t -> t
not v: negate the return value of a validator.

E.g. not File.existing is a validator that insists on a non-existent file.

val (&&) : t -> t -> t
a && b: conjunction of two validators.
val (||) : t -> t -> t
a || b: disjunction of two validators.