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 -> bool
valid t str
: is str
a valid t
?t
: the validatorstr
: the string to be validatedval mustbe : t -> string -> unit
mustbe t str
: check that str
is a valid t
and raise an exception if not.Invalid
if str
not a valid t
t
: the validatorstr
: the string to be validatedval asserted : t -> string -> string
asserted t str
: check that str
is a valid t
, raising an exception if not, and return str
.Invalid
if str
not a valid t
t
: the validatorstr
: the string to be validatedval make : string -> (string -> bool) -> t
make text predicate
: make a validator from an arbitrary predicateval 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
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 -> 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 formatterv
: the validatorval 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.