symbolType.ml 961 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
open IL

(* The symbol GADT is the union of the terminal and nonterminal GADTs. *)

(* The conventional name of the symbol GADT. *)

let tcsymbolgadt =
  "symbol"

let tsymbolgadt a =
  TypApp (tcsymbolgadt, [ a ])

13
(* The conventional names of the data constructors. *)
14 15 16 17 18 19 20 21 22

let dataT =
  "T"

let dataN =
  "N"

(* The definition of the symbol GADT. *)

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
let symbolgadtdef () =
  assert Settings.inspection;
  let a = "a" in
  let datadefs =
    {
      dataname = dataT;
      datavalparams = [ TokenType.ttokengadt (TypVar a) ];
      datatypeparams = Some [ TypVar a ]
    } ::
    {
      dataname = dataN;
      datavalparams = [ NonterminalType.tnonterminalgadt (TypVar a) ];
      datatypeparams = Some [ TypVar a ]
    } ::
    []
  in
  [ IIComment "The indexed type of terminal and nonterminal symbols.";
    IITypeDecls [{
      typename = tcsymbolgadt;
      typeparams = [ a ];
      typerhs = TDefSum datadefs;
      typeconstraint = None
    }]
  ]