printer.mli 2.37 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 16 17 18 19 20 21
(* A pretty-printer for [IL]. *)

module Make (X : sig

  (* This is the channel that is being written to. *)

  val f: out_channel

POTTIER Francois's avatar
POTTIER Francois committed
22
  (* [locate_stretches] controls the way we print OCaml stretches (types and
POTTIER Francois's avatar
POTTIER Francois committed
23 24 25 26
     semantic actions). If it is [Some dstfilename], where [dstfilename] is
     the name of the file that is being written, then we surround stretches
     with OCaml line number directives of the form # <line number> <filename>.
     If it is [None], then we don't. *)
POTTIER Francois's avatar
POTTIER Francois committed
27 28 29 30 31 32 33 34 35

  (* Providing line number directives allows the OCaml typechecker to report
     type errors in the .mly file, instead of in the generated .ml / .mli
     files. Line number directives also affect the dynamic semantics of any
     [assert] statements contained in semantic actions: when they are provided,
     the [Assert_failure] exception carries a location in the .mly file. As a
     general rule of thumb, line number directives should always be provided,
     except perhaps where we think that they decrease readability (e.g., in a
     generated .mli file). *)
36 37 38 39 40 41 42 43 44 45 46 47 48

  val locate_stretches: string option

end) : sig

  val program: IL.program -> unit

  val expr: IL.expr -> unit

  val interface: IL.interface -> unit

end

49
(* Common instantiations. In the following two functions, [locate_stretches]
POTTIER Francois's avatar
POTTIER Francois committed
50
   is [None], so no line number directives are printed. *)
51

52 53
val     print_expr: out_channel -> IL.expr -> unit
val string_of_expr:                IL.expr -> string