Module Acutis

This is the main API wrapper around the compiler internals (Acutis_internals).

type error = private Acutis_internals.Error.t

An error message.

exception Acutis_error of error

This is raised if any part of the process fails.

Declaring type schemes.

These are used primarily for component functions. The examples are in Acutis syntax.

val typescheme : (string * ty) Stdlib.Seq.t -> typescheme
val typescheme_empty : typescheme
val unknown : unit -> ty

The Acutis type _, compatible with any other type.

Primitive types.

val int : unit -> ty

Creates the primitive type int.

val float : unit -> ty

Creates the primitive type float.

val string : unit -> ty

Creates the primitive type string.

Parameterized types.

val nullable : ty -> ty

Wraps the given type as a nullable, e.g. ?int.

val list : ty -> ty

Wraps the given type as a list, e.g. [int].

val dict : ty -> ty

Wraps the given type as a dictionary, e.g. <int>.

Product types.

val tuple : ty Stdlib.Seq.t -> ty

Create a tuple from the sequence of types, e.g. (int, string, float).

val record : (string * ty) Stdlib.Seq.t -> ty

Create a record from the sequence of key-value pairs, e.g. {a: int, b: string, c: float}.

Sum types.

For types that accept an [ `Open | `Closed ] parameter, using `Open makes the type compatible with additional values, whereas `Closed restricts the type to only the values specified.

val enum_int : [ `Open | `Closed ] -> int Stdlib.Seq.t -> ty

Create an enumeration from the sequence of integers, e.g. @1 | @2 | @3.

val enum_string : [ `Open | `Closed ] -> string Stdlib.Seq.t -> ty

Create an enumeration from the sequence of strings, e.g. @"a" | @"b" | @"c".

val boolean : unit -> ty

Create the enumeration type false | true.

val false_only : unit -> ty

Create a type that can only be false.

val true_only : unit -> ty

Create a type that can only be true.

val union_string : [ `Open | `Closed ] -> string -> (string * (string * ty) Stdlib.Seq.t) Stdlib.Seq.t -> ty

union_int row field sequence creates a record where field is used to discriminate between different records in sequence. Each pair in sequence contains a value for field and then another sequence of key-value pairs that specify the rest of the record associated with that field. E.g.:

{@shape: "circle", radius: int} |
{@shape: "rectagle", height: int, width: int}
val union_int : [ `Open | `Closed ] -> string -> (int * (string * ty) Stdlib.Seq.t) Stdlib.Seq.t -> ty

The same as union_string, except that the field's values are integers.

val union_boolean : string -> f:(string * ty) Stdlib.Seq.t -> t:(string * ty) Stdlib.Seq.t -> ty

union_boolean field ~f ~t creates a record where if field is false then the record has the shape of f and if field is true then the record has the shape of t.

val union_false_only : string -> (string * ty) Stdlib.Seq.t -> ty

This is similar to union_boolean except that the field can only be false.

val union_true_only : string -> (string * ty) Stdlib.Seq.t -> ty

This is similar to union_boolean except that the field can only be true.

Compiling templates.

A template component. It is either from Acutis source code or it is 'a. 'a may be a function or data to load a function, depending on how the template is to be rendered.

val comp_parse : fname:string -> name:string -> Stdlib.Lexing.lexbuf -> 'a comp

Parses Acutis source into a template component but doesn't type-check yet. fname is the file path and used here for debugging. name is the name the component is called in Acutis code.

val comp_fun : name:string -> typescheme -> 'a -> 'a comp

Convert a function (or possibly data for loading a function) into a template component.

type 'a comps_compiled = private 'a Acutis_internals.Compile.Components.t

A group of compiled and linked components.

val comps_compile : 'a comp Stdlib.Seq.t -> 'a comps_compiled

Type-checks, optimizes, and links the components.

val comps_empty : 'a comps_compiled
type parsed

A template that's been parsed but not type-checked, optimized, or linked yet.

val parse : fname:string -> Stdlib.Lexing.lexbuf -> parsed
type 'a compiled = private 'a Acutis_internals.Compile.t

A completely compiled template.

val compile : 'a comps_compiled -> parsed -> 'a compiled

Type-checks, optimizes, and links the template with its components.

val compile_interface : fname:string -> Stdlib.Lexing.lexbuf -> typescheme

Parses and type-checks an interface with no template.

val get_typescheme : 'a compiled -> typescheme

Rendering templates with OCaml.

module type PROMISE = sig ... end

A promise interface for async operations.

module type DECODABLE = sig ... end

Decode and encode input data.

module Render (Promise : PROMISE) (Data : DECODABLE) : sig ... end

A functor that builds a render implementation for a given promise interface and a given decodable input type.

val render_string : (module DECODABLE with type t = 'a) -> ('a -> string) compiled -> 'a -> string

A simpler version of Render that only requires a decodable module and outputs a string.

Printing templates as JavaScript modules.

type js_import

Information to import an external JavaScript function.

val js_import : module_path:string -> function_path:string -> js_import
val cjs : Stdlib.Format.formatter -> js_import compiled -> unit

Print a template as a CommonJS module.

val esm : Stdlib.Format.formatter -> js_import compiled -> unit

Print a template as an ECMAScript module.

Printing debugging information.

val pp_error : Stdlib.Format.formatter -> error -> unit

Pretty-print an error message.

val pp_typescheme : Stdlib.Format.formatter -> typescheme -> unit

Pretty-print a type scheme in Acutis syntax.

val pp_ast : Stdlib.Format.formatter -> parsed -> unit

Pretty-print a template's abstract syntax tree in S-expression syntax.

val pp_compiled : Stdlib.Format.formatter -> 'a compiled -> unit

Pretty-print a fully-compiled template in S-expression syntax.

val pp_instructions : (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a compiled -> unit

Pretty-print runtime instructions in S-expression syntax.

val pp_js_import : Stdlib.Format.formatter -> js_import -> unit

Pretty-print JavaScript import data in S-expression syntax.