module Kwvalid:sig..end
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.
type t = {
|
t : |
(* |
description of what this validator considers valid (a noun)
| *) |
|
f : |
(* |
test function
| *) |
exception Invalid of string * string
val error : Format.formatter -> string -> string -> unit
val string_of_exn : exn -> string
Validators are Boolean functions; you can call t.f directly, or
use one of these convenience functions.
val valid : t -> string -> boolvalid t str: is str a valid t?t : the validatorstr : the string to be validatedval mustbe : t -> string -> unitmustbe t str: check that str is a valid t and raise an exception if not.Invalid if str not a valid tt : the validatorstr : the string to be validatedval asserted : t -> string -> stringasserted t str: check that str is a valid t, raising an exception if not, and return str.Invalid if str not a valid tt : the validatorstr : the string to be validatedval make : string -> (string -> bool) -> tmake text predicate: make a validator from an arbitrary predicateval always : talways considers any argument string valid.val any : tany considers any argument string valid.val never : tnever never considers any argument string valid.val enum : string list -> tenum list: considers valid any string in the given list.module Combinator:sig..end
module Number:
module Num:sig..end
module String:sig..end
module B:sig..end
module File:sig..end
module Directory:sig..end
module Json:sig..end
val warning : Format.formatter -> t -> twarning v: convert the validator v into one that always succeeds, but generates a warning
on the formatter fmt if the validation fails.fmt : the formatterv : the validatorval not : t -> tnot 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 -> ta && b: conjunction of two validators.val (||) : t -> t -> ta || b: disjunction of two validators.