action.mli 3.29 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
open Keyword

16 17 18 19 20 21 22
(** Semantic action's type. *)
type t

(** [compose x a1 a2] builds the action [let x = a1 in a2]. This
    feature is used during the processing of the %inline keyword. *)
val compose : string -> t -> t -> t

POTTIER Francois's avatar
POTTIER Francois committed
23 24 25 26
(** [bind p x a] binds the OCaml pattern [p] to the OCaml variable [x] in the
   semantic action [a]. Therefore, it builds the action [let p = x in a]. *)
val bind: IL.pattern -> string -> t -> t

27 28 29 30 31 32 33 34 35
(* [define keyword keywords f action] defines away the keyword [keyword].
   It is removed from the set of keywords of this semantic action; the
   set [keywords] is added in its place. The body of the semantic action
   is transformed by the function [f], which typically wraps it in some
   new [let] bindings. *)

val define: keyword -> KeywordSet.t -> (IL.expr -> IL.expr) -> t -> t

(* Variable-to-variable substitutions, used by [rename], below. *)
36

37 38 39
type subst =
  (string * string) list

40 41 42
(* [Subject/where] pairs, as defined in [Keyword], encode a position
   keyword. *)

43
type sw =
44
  subject * where
45

46 47 48 49 50 51 52 53 54 55
(** [rename f phi a] applies to the semantic action [a] the renaming [phi] as
    well as the transformations decided by the function [f]. The function [f] is
    applied to each (not-yet-renamed) keyword and may decide to transform it, by
    returning [Some _], or to not transform it, by returning [None]. (In the
    latter case, [phi] still applies to the keyword.) *)
val rename:
  (sw -> sw option) ->
  subst ->
  t ->
  t
56 57 58 59 60 61 62 63 64 65 66 67

(** Semantic actions are translated into [IL] code using the
    [IL.ETextual] and [IL.ELet] constructors. *)
val to_il_expr: t -> IL.expr

(** A semantic action might be the inlining of several others. The
    filenames of the different parts are given by [filenames a]. This
    can be used, for instance, to check whether all parts come from
    the standard library. *)
val filenames: t -> string list

(** [keywords a] is the set of keywords used in the semantic action [a]. *)
68
val keywords: t -> KeywordSet.t
69 70 71 72

(** [from_stretch s] builds an action out of a textual piece of code. *)
val from_stretch: Stretch.t -> t

POTTIER Francois's avatar
POTTIER Francois committed
73 74 75
(** [from_il_expr] converts an [IL] expression into a semantic action. *)
val from_il_expr: IL.expr -> t

76
(** Test whether the keyword [$syntaxerror] is used in the action. *)
77 78
val has_syntaxerror: t -> bool

79
(** Test whether the keyword [$endpos($0)] is used in the action. *)
80
val has_beforeend: t -> bool