| 1 | open! Base |
| 2 | open! Ppxlib |
| 3 | |
| 4 | (** Sexp conversion function, expressed as either a single expression or as a collection |
| 5 | of [match] cases. Expressing as cases rather than wrapping directly in [pexp_function_cases] |
| 6 | allows us to simplify some expressions built on this. *) |
| 7 | type t |
| 8 | |
| 9 | (** Construct [t] from a list of pattern/expression cases. *) |
| 10 | val of_lambda : cases -> t |
| 11 | |
| 12 | (** Construct [t] from an identifier, possibly applied to arguments. Raise on any other |
| 13 | form of expression. *) |
| 14 | val of_reference_exn : expression -> t |
| 15 | |
| 16 | (** Convert [t] to an expression. *) |
| 17 | val to_expression : t -> loc:location -> expression |
| 18 | |
| 19 | (** Convert [t] to an expression that is a syntactic value, i.e. a constant, identifier, |
| 20 | or lambda expression that does no "work", can can be preallocated, and works in the |
| 21 | context of a [let rec]. *) |
| 22 | val to_value_expression |
| 23 | : t |
| 24 | -> loc:location |
| 25 | -> rec_flag:rec_flag |
| 26 | -> values_being_defined:Set.M(String).t |
| 27 | -> expression |
| 28 | |
| 29 | (** Apply [t] to an argument. *) |
| 30 | val apply |
| 31 | : t |
| 32 | -> loc:location |
| 33 | -> expression (** argument [t] is applied to *) |
| 34 | -> expression |
| 35 | |
| 36 | (** Wrap [t] in [let]-bindings. *) |
| 37 | val bind : t -> value_binding list -> t |
| 38 | |
| 39 | (** Wrap [t] in [let open .. in] with type declarations. *) |
| 40 | val bind_types : t -> type_declaration list -> t |
| 41 | |
| 42 | module Apply_all : sig |
| 43 | type t = |
| 44 | { bindings : value_binding list |
| 45 | ; arguments : pattern list |
| 46 | ; converted : expression list |
| 47 | } |
| 48 | end |
| 49 | |
| 50 | (** Applies each [t] to a fresh variable, and binds the results to fresh variables. |
| 51 | Returns the corresponding [value_binding]s, patterns for the argument variables, and |
| 52 | expressions for the result variables. *) |
| 53 | val apply_all : t list -> loc:location -> Apply_all.t |