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.
These are used primarily for component functions. The examples are in Acutis syntax.
type ty = private Acutis_internals.Typechecker.Type.t
type typescheme = private Acutis_internals.Typechecker.Type.scheme
val typescheme : (string * ty) Stdlib.Seq.t -> typescheme
val typescheme_empty : typescheme
val unknown : unit -> ty
The Acutis type _
, compatible with any other type.
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
.
Create a tuple from the sequence of types, e.g. (int, string, float)
.
Create a record from the sequence of key-value pairs, e.g. {a: int, b: string, c: float}
.
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.
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
.
This is similar to union_boolean
except that the field can only be false
.
This is similar to union_boolean
except that the field can only be true
.
type 'a comp = private 'a Acutis_internals.Compile.Components.source
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
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
module type PROMISE = sig ... end
A promise interface for async operations.
module type DECODABLE = sig ... end
Decode and encode input data.
A functor that builds a render implementation for a given promise interface and a given decodable input type.
A simpler version of Render
that only requires a decodable module and outputs a string.
val js_import : module_path:string -> function_path:string -> js_import
Print a template as a CommonJS module.
Print a template as an ECMAScript module.
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.