1 (* Goalfile Abstract Syntax Tree
2 * Copyright (C) 2019 Richard W.M. Jones
3 * Copyright (C) 2019 Red Hat Inc.
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.
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.
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.
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
30 (* This is not the normal Map.merge function. *)
31 val merge : 'a t -> 'a t -> 'a t
34 (** Location where we parsed from $loc = $startpos, $endpos *)
35 type loc = Lexing.position * Lexing.position
37 val print_loc : out_channel -> loc -> unit
38 val string_loc : unit -> loc -> string
40 (** An environment is a set of variable and goal definitions, mapping
41 variable or goal name -> expression. *)
44 | PTactic of loc * id * substs list
45 (** match tactic such as *file ("filename") *)
47 | EGoalDefn of loc * goal
48 (** goal (params) = patterns : exprs code *)
49 | EFuncDefn of loc * func
50 (** function (params) = code *)
51 | ETacticDefn of loc * tactic
52 (** tactic (params) = code *)
53 | ECall of loc * id * expr list
54 (** call goal (params) or function (params) *)
55 | ETacticCtor of loc * id * expr list
56 (** constructor *tactic (params) *)
58 (** variable, or goal call with no parameters *)
59 | EList of loc * expr list
61 | ESubsts of loc * substs
62 (** string with %-substitutions *)
63 | EConstant of loc * constant
64 (** constant expression, such as a plain string, int, boolean, etc. *)
67 and goal = param_decl list * pattern list * expr list * code option
68 and func = param_decl list * returning * code
69 and tactic = param_decl list * code
70 and param_decl = id (** goal/func/tactic parameter. *)
73 and returning = RetExpr | RetStrings | RetString
74 and substs = subst list
77 (** String literal part. *)
79 (** %-substitution. *)
81 val getvar : env -> loc -> id -> expr
82 (** Look up a variable in the environment. Raise [Failure _]
85 val getgoal : env -> loc -> id -> goal
86 (** Look up a goal in the environment. Raise [Failure _] if not
87 found or if the named variable is not a goal. *)
89 val getfunc : env -> loc -> id -> func
90 (** Look up a function in the environment. Raise [Failure _] if not
91 found or if the named variable is not a function. *)
93 val gettactic : env -> loc -> id -> tactic
94 (** Look up a tactic in the environment. Raise [Failure _] if not
95 found or if the named variable is not a tactic. *)
97 (** This is used for incrementally building Ast.substs in the parser. *)
100 val create : unit -> t
101 val get : t -> substs
102 val add_char : t -> char -> unit
103 val add_string : t -> string -> unit
104 val add_var : t -> string -> unit
107 (** %a formatters. *)
108 val print_env : out_channel -> env -> unit
109 val string_pattern : unit -> pattern -> string
110 val string_expr : unit -> expr -> string
111 val print_expr : out_channel -> expr -> unit