Module Excmd.AST

Describing structures

Some of our data-structures provide conversion functions to produce alternative formats of themselves. These are automatically generated at compile-time by PPX preprocessors in OCaml.

Unfortunately, we use different data-structures per compile-target: in native OCaml, we use {{:https://github.com/ocaml-ppx/ppx_deriving_yojson} ppx_deriving_yojson} to produce a value of type Yojson.Basic.json; but when being compiled to JavaScript, we use BuckleScript's jsConverter tooling to generate the built-in Js.t type. These generators also produce functions of different names: to_yojson is available on the native side, and tToJs on the BuckleScript side.

Due to the fact that the relevant types differ between platforms, fully generic code involving alternative-format representations like the above isn't clean and easy. Both of the above flavours of conversion-function will raise a runtime exception if called on a platform that doesn't support them; if you need to, you can catch said exception and swap implementations based on that.

exception WrongPlatform of [ `JavaScript | `Native ] * string
val unavailable_on : [ `JavaScript | `Native ] -> string -> 'a
val tOfJs : 'a -> 'b
val tToJs : 'a -> 'b
val expressionOfJs : 'a -> 'b
val expressionToJs : 'a -> 'b
val to_yojson : 'a -> 'b
val of_yojson : 'a -> 'b
val expression_to_yojson : 'a -> 'b
val expression_of_yojson : 'a -> 'b
type 'a unresolved =
| Unresolved
| Resolved of 'a
| Absent
val unresolved_to_yojson : a. ('a -> Yojson.Safe.json) -> 'a unresolved -> Yojson.Safe.json
type 'a or_subexpr =
| Sub of expression
| Literal of 'a
type flag = {
name : string;
mutable payload : string or_subexpr unresolved;
}
type arg =
| Positional of string or_subexpr
| Flag of flag
type expression = {
count : int;
cmd : string or_subexpr;
mutable rev_args : arg list;
}
val or_subexpr_to_yojson : a. ('a -> Yojson.Safe.json) -> 'a or_subexpr -> Yojson.Safe.json
val flag_to_yojson : flag -> Yojson.Safe.json
val arg_to_yojson : arg -> Yojson.Safe.json
val expression_to_yojson : expression -> Yojson.Safe.json
type t = {
expressions : expression array;
}
val to_yojson : t -> Yojson.Safe.json
val make_expression : ?⁠count:string -> cmd:string or_subexpr -> rev_args:arg list -> expression
val pipe_last : from:expression -> into:expression -> expression
val copy_string_or_subexpr : string or_subexpr -> string or_subexpr
val copy_flag : flag -> flag
val copy_arg : arg -> arg
val copy_expression : expression -> expression
val copy : t -> t
val pp_bs : 'a -> 'b
val pp_native : t -> unit
val pp : t -> unit
val pp_expression_bs : 'a -> 'b
val pp_expression_native : expression -> unit
val pp_expression : expression -> unit
val is_literal : 'a or_subexpr -> bool
val get_literal_exn : 'a or_subexpr -> 'a
val get_sub_exn : 'a or_subexpr -> expression