Module Melange_compiler_libs.Signature_group

Iterate on signature by syntactic group of items

Classes, class types and private row types adds ghost components to the signature where they are defined.

When editing or printing a signature it is therefore important to identify those ghost components.

This module provides type grouping together ghost components with the corresponding core item (or recursive group) and the corresponding iterators.

type sig_item = {
  1. src: Types.signature_item,
    /*

    the syntactic item

    */
  2. post_ghosts: list(Types.signature_item),
    /*

    ghost classes types are post-declared

    */
};

Classes and class types generate ghosts signature items, we group them together before printing

let flatten: sig_item => Types.signature;

flatten sig_item is x.src :: x.post_ghosts

type core_rec_group =
  1. | Not_rec(sig_item)
  2. | Rec_group(list(sig_item))
;

A group of mutually recursive definition

let rec_items: core_rec_group => list(sig_item);

rec_items group is the list of sig_items in the group

type rec_group = {
  1. pre_ghosts: list(Types.signature_item),
  2. group: core_rec_group,
};

Private #row types are manifested as a sequence of definitions preceding a recursive group, we collect them and separate them from the syntactic recursive group.

let next: Types.signature => option((rec_group, Types.signature));

The sequence seq signature iterates over signature rec_group by rec_group. The second element of the tuple in the full_seq case is the not-yet traversed part of the signature.

let seq: Types.signature => Stdlib.Seq.t(rec_group);
let iter: (rec_group => unit) => Types.signature => unit;
let fold: ('acc => rec_group => 'acc) => 'acc => Types.signature => 'acc;
type in_place_patch = {
  1. ghosts: Types.signature,
    /*

    updated list of ghost items

    */
  2. replace_by: option(Types.signature_item),
    /*

    replacement for the selected item

    */
};

Describe how to amend one element of a signature

let replace_in_place: (ghosts:Types.signature => Types.signature_item => option(('a, in_place_patch))) => Types.signature => option(('a, Types.signature));

!replace_in_place patch sg replaces the first element of the signature for which patch ~ghosts component returns Some (value,patch). The ghosts list is the current prefix of ghost components associated to component