Module Incr_dom_widgets.Sexp_form
module Init : sig ... endThis is a module for building forms that allow the user to edit complicated types (for example, configs).
val to_interactive : init:'a Init.t -> 'a t -> 'a Core_kernel.Or_error.t Interactive.t
module Case : sig ... endA
'a Case.tis implemented as a'a Sexp_form.t. When you create a case from a variant constructor for variantFoo.t, say a constructor for typeint * string, you get a(int -> string -> Foo.t) Case.t.
module Record_builder : sig ... end('record, 'a) Record_builder.tis implemented as a'a Sexp_form.t. The'recordonly exists for additional type safety.
module Record_field : sig ... end('record, 'a) Record_field.tis implemented as a'a Sexp_form.t. The'recordonly exists for additional type safety.
module Primitives : sig ... endval map : 'a t -> a_to_b:('a -> 'b) -> b_to_a:('b -> 'a) -> sexp_of_a:('a -> Core_kernel.Sexp.t) -> b_of_sexp:(Core_kernel.Sexp.t -> 'b) -> 'b tTo map from
'a tto'b t, we need to be able to parse default values of type'b.Since we parse default values as sexps, this entails some conversion back and forth.
If
a_to_bthrows, this function will catch it and display the error to the user.
val map_that_can_fail : 'a t -> a_to_b:('a -> 'b Core_kernel.Or_error.t) -> b_to_a:('b -> 'a) -> sexp_of_a:('a -> Core_kernel.Sexp.t) -> b_of_sexp:(Core_kernel.Sexp.t -> 'b) -> 'b tIf this returns an error, the error will be displayed before the form element.
If
a_to_bthrows, this function will catch it and display the error to the user.
module Unsafe : sig ... endThis module is "Unsafe" because it relies on the user to ensure that when they map from 'a to 'b, 'a and 'b have the same sexp representation.
val validate : where:[ `Before | `After ] -> 'a t -> f:('a -> unit Core_kernel.Or_error.t) -> 'a tValidates the value in the form, displaying the provided error if it is invalid.
whereindicates whether the error should be displayed before or after the form element. It's recommended to use `After for errors which are right next to the area where the user inputs the data, and `Before for errors in complicated types which comprise many input fields.
val validate_interactive : where:[ `Before | `After ] -> 'a t -> 'b Interactive.t -> f:('a -> 'b -> unit Core_kernel.Or_error.t) -> 'a tSame as
validate, but more suited for validating properties which depend on external, changing state.Note that an
Incrcan be converted to anInteractiveusingInteractive.of_incr.
val handle_error : where:[ `Before | `After ] -> 'a Core_kernel.Or_error.t t -> 'a thandle_errordisplays the error, if there is one. If there is no error, it does nothing.validateis a wrapper aroundhandle_error.
val test : form:'a t -> value:'a -> sexp_of_t:('a -> Core_kernel.Sexp.t) -> equal:('a -> 'a -> bool) -> on_failure:[ `Print | `Raise ] -> unitVerifies that the provided
formcan parsevalue. Intended for expect tests.
val test_list : form:'a t -> values:'a list -> sexp_of_t:('a -> Core_kernel.Sexp.t) -> equal:('a -> 'a -> bool) -> on_failure:[ `Print | `Raise ] -> unitFor convenience -- it just calls
testfor each value.
val test_sequence : form:'a t -> values:'a Core_kernel.Sequence.t -> sexp_of_t:('a -> Core_kernel.Sexp.t) -> equal:('a -> 'a -> bool) -> on_failure:[ `Print | `Raise ] -> unitFor convenience -- it just calls
testfor each value.