tokenType.mli 2.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
(******************************************************************************)
(*                                                                            *)
(*                                   Menhir                                   *)
(*                                                                            *)
(*                       François Pottier, Inria Paris                        *)
(*              Yann Régis-Gianas, PPS, Université Paris Diderot              *)
(*                                                                            *)
(*  Copyright Inria. All rights reserved. This file is distributed under the  *)
(*  terms of the GNU General Public License version 2, as described in the    *)
(*  file LICENSE.                                                             *)
(*                                                                            *)
(******************************************************************************)

14 15
(* This module deals with the definitions of the type(s) that describe
   the tokens and the terminal symbols. *)
16

17 18 19 20
(* By default, following [ocamlyacc], we produce just one type, [token],
   which describes the tokens. A token contains a tag (a terminal symbol)
   and possibly a semantic value. *)

21 22 23
(* In addition to that, in [--inspection] mode only, we produce a GADT which
   describes the terminal symbols. A terminal symbol is just a tag; it does
   not carry a semantic value. *)
24 25 26

(* In this module, we also deal with [--only-tokens] and [--external-tokens].
   If [--only-tokens] is specified on the command line, [produce_tokentypes]
27 28 29
   emits the type definition(s) and exit. If [--external-tokens M] is set,
   then the token type and the token GADT are defined as abbreviations for
   [M.token] and ['a M.terminal]. *)
30

31
(* The conventional name of the [token] type, for use by the code
32
   generators. *)
33 34 35

val ttoken: IL.typ

36 37 38 39 40 41
(* [tokendata] maps the name of a token to a data constructor of the [token]
   type. (If [--external-tokens] is set, then it prefixes its argument with an
   appropriate OCaml module name. Otherwise, it is the identity.) *)

val tokendata: string -> string

42 43
(* The conventional name of the [terminal] type, a.k.a. the token GADT. This
   is an indexed type (i.e., it has one type parameter). Its data constructors
44
   carry zero value arguments. *)
45

46
val tctokengadt: string
47
val ttokengadt: IL.typ -> IL.typ
48

49 50 51 52 53
(* [tokengadtdata] maps the name of a token to a data constructor of the token
   GADT. *)

val tokengadtdata: string -> string

54
(* The definitions of the token type and of the token GADT, for use by the
55
   code generators. Each of these lists defines zero or one type. *)
56

57 58
val tokentypedef: BasicSyntax.grammar -> IL.interface
val tokengadtdef: BasicSyntax.grammar -> IL.interface
59

60 61 62
(* If [--only-tokens] is set, then [produce_tokentypes] writes the type
   definitions to the [.ml] and [.mli] files and stops Menhir. Otherwise,
   it does nothing. *)
63

64
val produce_tokentypes: BasicSyntax.grammar -> unit
65