Module Atd_ast

module Atd_ast: sig .. end
Abstract syntax tree (AST) representing ATD data

type loc = Lexing.position * Lexing.position 
A location in the source code.
exception Atd_error of string
Exception raised by functions of the atd library and indicating errors.
type annot = annot_section list 
An annotation, consisting of a sequence of sections. Atd_annot provides utilities for handling annotations.
type annot_section = string * (loc * annot_field list) 
represents a single annotation within edgy brackets. <"foo" bar baz="123"> in ATD syntax translates to:
("foo", (loc1, [ ("bar", (loc2, None));
                 ("baz", (loc3, Some "123")) ] ))

type annot_field = string * (loc * string option) 
An annotation field, i.e. a key with an optional value within an annotation.
type full_module = module_head * module_body 
Contents of an ATD file.
type module_head = loc * annot 
The head of an ATD file is just a list of annotations.
type module_body = module_item list 
The body of an ATD file is a list of type definitions. Type definitions are implicitely mutually recursive. They can be sorted based on dependencies using Atd_util.tsort.
type module_item = [ `Type of type_def ] 
There is currently only one kind of module items, that is single type definitions.
type type_def = loc * (string * type_param * annot) *
type_expr
A type definition.
type type_param = string list 
List of type variables without the tick.
type type_expr = [ `List of loc * type_expr * annot
| `Name of loc * type_inst * annot
| `Nullable of loc * type_expr * annot
| `Option of loc * type_expr * annot
| `Record of loc * field list * annot
| `Shared of loc * type_expr * annot
| `Sum of loc * variant list * annot
| `Tuple of loc * cell list * annot
| `Tvar of loc * string
| `Wrap of loc * type_expr * annot ]
A type expression is one of the following:
type type_inst = loc * string * type_expr list 
A type name and its arguments
type variant = [ `Inherit of loc * type_expr
| `Variant of
loc * (string * annot) * type_expr option ]
A single variant or an inherit statement. `Inherit statements can be expanded into variants using Atd_inherit or at loading time using the inherit_variant option offered by the Atd_util functions.
type cell = loc * type_expr * annot 
Tuple cell. Note that annotations placed before the type expression are supported and represented here, such as the third cell in (float * float * <ocaml default="0.0"> float).
type field_kind = [ `Optional | `Required | `With_default ] 
Different kinds of record fields based on the Sample ATD file:
type level = [ Beginner | Advanced | Expert ]

type user = {
  id : string;

  ?name : string option;
    (* Field may be omitted when no value is set, if permitted
       by the target language. *)

  ~websites : string list;
    (* Implicit default: empty list.
       Field may be omitted if the field value is
       equal to the default value and the
       target language permits it. *)

  ~level <ocaml default="`Beginner"> : level;
    (* Explicit default for `ocaml'.
       For instance there is no `json' annotation because
       the default for undefined `JSON' fields would be to omit them. *)
}

type field = [ `Field of
loc * (string * field_kind * annot) *
type_expr
| `Inherit of loc * type_expr ]
A single record field or an inherit statement. `Inherit statements can be expanded into fields using Atd_inherit or at loading time using the inherit_fields option offered by the Atd_util functions.
val loc_of_type_expr : type_expr -> loc
Extract the source location of any type expression.
val set_type_expr_loc : loc -> type_expr -> type_expr
Replace the location of the given expression. This is a shallow substitution. Sub-expressions are not affected.
val string_of_loc : loc -> string
Convert a location into a human-readable string such as File "foo.atd", line 123, characters 40-45.
val error : string -> 'a
error s is a shorthand for raise (Atd_error s).
val error_at : loc -> string -> 'a
error_at loc s raises Atd_error s' where s' is the location followed by s.
val dummy_loc : loc
Dummy value for predefined constructs that are not associated with a useful source location. Should not show up in error messages.
val annot_of_type_expr : type_expr -> annot
Return the annotations associated with a type expression. Note that there can be annotations in a variety of places, not just after type expressions.
val map_annot : (annot -> annot) -> type_expr -> type_expr
Replacement of the annotations associated with a type expression. This is a shallow transformation. Sub-expressions are not affected.
val map_all_annot : (annot -> annot) ->
full_module -> full_module
Replacement of all annotations occurring in an ATD module.
val fold : (type_expr -> 'a -> 'a) -> type_expr -> 'a -> 'a
Iteration and accumulation over each type_expr node within a given type_expr.
val extract_type_names : ?ignorable:string list -> type_expr -> string list
Extract all the type names occurring in a type expression under `Name, without duplicates.
ignorable : specifies a list of type names to exclude from the result
val is_parametrized : type_expr -> bool
Test whether a type expression contains type variables (`Tvar).