Module Pa_type_conv
val get_conv_path : unit -> string
get_conv_path ()
Returns the name to module containing a type
as required for error messages.
val add_generator : ?is_exn:bool -> string -> bool -> Camlp4.PreCast.Ast.ctyp -> Camlp4.PreCast.Ast.str_item -> unit
add_generator ?is_exn name gen
adds the code generator gen
,
which maps type or exception declarations to structure items, where
is_exn
specifies whether the declaration is an exception. Note that
the original type/exception declarations get added automatically in
any case.
is_exn =
false
val add_generator_with_arg : ?is_exn:bool -> string -> 'a Camlp4.PreCast.Gram.Entry.t -> 'a option -> bool -> Camlp4.PreCast.Ast.ctyp -> Camlp4.PreCast.Ast.str_item -> unit
add_generator_with_arg ?is_exn name entry generator
same as
add_generator
, but the generator may accept an argument, which is
parsed with entry
.
val rm_generator : ?is_exn:bool -> string -> unit
rm_generator ?is_exn name
removes the code generator named name
for types if is_exn
is false
, or exceptions otherwise.
is_exn =
false
val add_sig_generator : ?delayed:bool -> ?is_exn:bool -> string -> bool -> Camlp4.PreCast.Ast.ctyp -> Camlp4.PreCast.Ast.sig_item -> unit
add_sig_generator ?delayed ?is_exn name gen
adds the code generator gen
,
which maps type or exception declarations to signature items, where
is_exn
specifies whether the declaration is an exception. Note that the
original type/exception declarations get added automatically in any case. If
delayed
is set to true, the output of this generator is appended to the
signature in which it's defined
delayed =
false
is_exn =
false
val add_sig_generator_with_arg : ?delayed:bool -> ?is_exn:bool -> string -> 'a Camlp4.PreCast.Gram.Entry.t -> 'a option -> bool -> Camlp4.PreCast.Ast.ctyp -> Camlp4.PreCast.Ast.sig_item -> unit
add_sig_generator_with_arg ?delayed ?is_exn name entry generator
same as
add_sig_generator
, but the generator may accept an argument,
which is parsed with entry
.
val rm_sig_generator : ?is_exn:bool -> string -> unit
rm_sig_generator ?is_exn name
removes the signature code generator named
name
for types if is_exn
is false
, or exceptions otherwise.
is_exn =
false
val add_record_field_generator : string -> record_field_generator -> unit
add_record_field_generator gen_name gen
adds the record field code
generator gen
with name gen_name
, which acts on the location
identifying the record field.
val add_record_field_generator_with_arg : string -> 'a Camlp4.PreCast.Gram.Entry.t -> 'a option -> record_field_generator -> unit
add_record_field_generator_with_arg name entry generator
same as
add_record_field_generator
, but the generator
takes an argument,
which is parsed with entry
. If None
is passed to the generator,
parsing of the argument failed, otherwise Some arg
will be passed,
where arg
is the successfully parsed argument.
val rm_record_field_generator : string -> unit
rm_record_field_generator name
removes the record field code generator
named name
.
val add_sig_set : ?is_exn:bool -> string -> set:string list -> unit
add_sig_set ?is_exn id ~set
adds the generator id
to the list
of generators for signatures.
This generator will behave as if is all the generators from set
had been given instead. Any duplicate arising from repeatedly
expanding such generators are removed.
If is_exn
, then it is a generator for exception declaration, or
else it is a generator for type declaration.
val add_str_set : ?is_exn:bool -> string -> set:string list -> unit
add_str_set ?is_exn id ~set
behaves exactly like
add_sig_set ?is_exn id ~set
but for structure items instead of
signatures items.
val add_set : kind:TODO: a -> is_exn:TODO: b -> string -> set:string list -> unit
add_set ~kind ~is_exn id ~set
is a shorthand for doing multiple
calls to add_str_set
and add_sig_set
val hash_variant : string -> int
hash_variant str
Returns the integer encoding a variant tag with
name
str
.
module Gen : sig
val regular_constr_of_revised_constr : string -> string
val gensym : ?prefix:string -> unit -> string
gensym ?prefix ()
generates a fresh variable name with prefix
.
When used with the default parameters, it will return: _x__001
,
_x__002
, _x__003
, ...
prefix default = "_x"
val abstract : Camlp4.PreCast.Ast.Loc.t -> Camlp4.PreCast.Ast.patt list -> Camlp4.PreCast.Ast.expr -> Camlp4.PreCast.Ast.expr
abstract loc patts body
takes a location loc
, a pattern list
patts
, and an expression body
.
Returns a function expression
that takes the patterns as arguments, and binds them in
body
.
val apply : Camlp4.PreCast.Ast.Loc.t -> Camlp4.PreCast.Ast.expr -> Camlp4.PreCast.Ast.expr list -> Camlp4.PreCast.Ast.expr
apply loc f_expr arg_exprs
takes a location loc
, an expression
f_expr
representing a function, and a list of argument expressions
arg_exprs
.
Returns an expression in which the function is
applied to its arguments.
val switch_tp_def : alias:Camlp4.PreCast.Ast.Loc.t -> Camlp4.PreCast.Ast.ctyp -> 'a -> sum:Camlp4.PreCast.Ast.Loc.t -> Camlp4.PreCast.Ast.ctyp -> 'a -> record:Camlp4.PreCast.Ast.Loc.t -> Camlp4.PreCast.Ast.ctyp -> 'a -> variants:Camlp4.PreCast.Ast.Loc.t -> Camlp4.PreCast.Ast.ctyp -> 'a -> mani:Camlp4.PreCast.Ast.Loc.t -> Camlp4.PreCast.Ast.ctyp -> Camlp4.PreCast.Ast.ctyp -> 'a -> nil:Camlp4.PreCast.Ast.Loc.t -> 'a -> Camlp4.PreCast.Ast.ctyp -> 'a
switch_tp_def ~alias ~sum ~record ~variants ~mani tp_def
takes a handler function for each kind of type definition and
applies the appropriate handler when tp_def
matches.
val type_is_recursive : ?stop_on_functions:bool -> ?short_circuit:Camlp4.PreCast.Ast.ctyp -> bool option -> string -> Camlp4.PreCast.Ast.ctyp -> bool
type_is_recursive ?short_circuit id tp
Returns whether the type
tp
with name id
refers to itself, assuming that it is not mutually recursive with
another type.
short_circuit allows you to override the search for certain
type expressions.
stop_on_functions allows to disregard the recursive occurences appearing in
arrow types. The default is to disregard them.
end
module Rewrite_tds : sig
val sig_ : Camlp4.PreCast.Ast.Loc.t -> bool -> Camlp4.PreCast.Ast.ctyp -> Camlp4.PreCast.Ast.sig_item
sig_ loc rec_ typedefs
rewrites the given type definition to make it either
recursive or non recursive.
For instance, the parser calls sig_ loc false (TyDcl (_, t, [], t, []))
when it
encouters type t = t
and calls sig_ loc true (TyDcl (_, t, [], t, []))
when it
encouters type nonrec t = t
in signatures.
end