Ast: Remove functions which were moved to Eval module.
[goals.git] / src / ast.mli
1 (* Goalfile Abstract Syntax Tree
2  * Copyright (C) 2019 Richard W.M. Jones
3  * Copyright (C) 2019 Red Hat Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *)
19
20 module Env : sig
21   type key = string
22   type 'a t
23   val empty: 'a t
24   val add: key -> 'a -> 'a t -> 'a t
25   val find: key -> 'a t -> 'a
26   val fold: (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
27   val filter: (key -> 'a -> bool) -> 'a t -> 'a t
28   val bindings: 'a t -> (key * 'a) list
29
30   (* This is not the normal Map.merge function. *)
31   val merge : 'a t -> 'a t -> 'a t
32 end
33
34 (** Location where we parsed from $loc = $startpos, $endpos *)
35 type loc = Lexing.position * Lexing.position
36 val noloc : loc
37 val print_loc : out_channel -> loc -> unit
38 val string_loc : unit -> loc -> string
39
40 (** An environment is a set of variable and goal definitions, mapping
41     variable or goal name -> expression. *)
42 type env = expr Env.t
43 and pattern =
44   (** match tactic such as *file ("filename") *)
45   | PTactic of loc * id * substs list
46 and expr =
47   (** goal (params) = patterns : exprs code *)
48   | EGoalDefn of loc * goal
49   (** tactic (params) = code *)
50   | ETacticDefn of loc * tactic
51   (** call goalname (params) etc. *)
52   | ECallGoal of loc * id * expr list
53   (** call *tactic (params) etc. *)
54   | ETacticCtor of loc * id * expr list
55   (** variable, or goal call with no parameters *)
56   | EVar of loc * id
57   (** list *)
58   | EList of loc * expr list
59   (** string with %-substitutions *)
60   | ESubsts of loc * substs
61   (** constant expression, such as a plain string, int, boolean, etc. *)
62   | EConstant of loc * constant
63 and constant =
64   | CString of string
65 and goal = param_decl list * pattern list * expr list * code option
66 and tactic = param_decl list * code
67   (** Goal/tactic parameter. *)
68 and param_decl = id
69 and id = string
70 and code = substs
71 and substs = subst list
72 and subst =
73   (** String literal part. *)
74   | SString of string
75   (** %-substitution. *)
76   | SVar of id
77
78 (** Look up a variable in the environment.  Raise [Failure _]
79     if not found. *)
80 val getvar : env -> loc -> id -> expr
81
82 (** Look up a goal in the environment.  Raise [Failure _] if not
83     found or if the named variable is not a goal. *)
84 val getgoal : env -> loc -> id -> goal
85
86 (** Look up a tactic in the environment.  Raise [Failure _] if not
87     found or if the named variable is not a tactic. *)
88 val gettactic : env -> loc -> id -> tactic
89
90 (** This is used for incrementally building Ast.substs in the parser. *)
91 module Substs : sig
92   type t
93   val create : unit -> t
94   val get : t -> substs
95   val add_char : t -> char -> unit
96   val add_string : t -> string -> unit
97   val add_var : t -> string -> unit
98 end
99
100 (** %a formatters. *)
101 val print_env : out_channel -> env -> unit
102 val string_pattern : unit -> pattern -> string
103 val string_expr : unit -> expr -> string
104 val print_expr : out_channel -> expr -> unit