From c46c3a5c7793753f2f15c1655517f3f9b8fee644 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 25 Dec 2019 14:30:38 +0000 Subject: [PATCH] Rename Ast.StringMap -> Ast.Env --- src/ast.ml | 6 +++--- src/ast.mli | 4 ++-- src/eval.ml | 12 ++++++------ src/main.ml | 2 +- src/parser.mly | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ast.ml b/src/ast.ml index 819e9ee..48ff6aa 100644 --- a/src/ast.ml +++ b/src/ast.ml @@ -20,7 +20,7 @@ open Lexing open Printf -module StringMap = Map.Make (String) +module Env = Map.Make (String) type loc = position * position let noloc = dummy_pos, dummy_pos @@ -31,7 +31,7 @@ let string_loc () loc = let print_loc fp loc = fprintf fp "%s" (string_loc () loc) -type env = expr StringMap.t +type env = expr Env.t and pattern = | PTactic of loc * id * substs list | PVar of loc * id @@ -85,7 +85,7 @@ let iter_with_commas ) xs let rec print_env fp env = - StringMap.iter (print_def fp) env + Env.iter (print_def fp) env and print_def fp name expr = match expr with diff --git a/src/ast.mli b/src/ast.mli index 3a42ec4..067d20a 100644 --- a/src/ast.mli +++ b/src/ast.mli @@ -17,7 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *) -module StringMap : sig +module Env : sig type key = string type 'a t val empty: 'a t @@ -36,7 +36,7 @@ val string_loc : unit -> loc -> string (** An environment is a set of variable and goal definitions, mapping variable or goal name -> expression. *) -type env = expr StringMap.t +type env = expr Env.t and pattern = (** match tactic such as file ("filename") *) | PTactic of loc * id * substs list diff --git a/src/eval.ml b/src/eval.ml index e928564..b8dbe54 100644 --- a/src/eval.ml +++ b/src/eval.ml @@ -28,7 +28,7 @@ and evaluate_target env = function (* Call a goal. *) | Ast.ECall (loc, name, args) -> let expr = - try Ast.StringMap.find name env + try Ast.Env.find name env with Not_found -> failwithf "%a: goal ‘%s’ not found" Ast.string_loc loc name in let goal = @@ -49,7 +49,7 @@ and evaluate_target env = function (* Look up the variable and substitute it. *) | Ast.EVar (loc, name) -> let expr = - try Ast.StringMap.find name env + try Ast.Env.find name env with Not_found -> failwithf "%a: variable ‘%s’ not found" Ast.string_loc loc name in evaluate_target env expr @@ -72,7 +72,7 @@ and evaluate_target env = function and run_goal_for_tactic loc env tactic const_args = (* Search across all goals for a matching tactic. *) let goals = - let env = Ast.StringMap.bindings env in + let env = Ast.Env.bindings env in filter_map (function (name, Ast.EGoal (loc, goal)) -> Some (name, goal) | _ -> None) env in @@ -132,7 +132,7 @@ and run_goal loc env name args (params, patterns, deps, code) = failwithf "%a: calling goal ‘%s’ with wrong number of arguments" Ast.string_loc loc name in let env = - List.fold_left (fun env (k, v) -> Ast.StringMap.add k v env) + List.fold_left (fun env (k, v) -> Ast.Env.add k v env) env params in (* Evaluate the dependencies first. *) @@ -161,7 +161,7 @@ and simplify env = function | Ast.EVar (loc, name) -> let expr = - try Ast.StringMap.find name env + try Ast.Env.find name env with Not_found -> failwithf "%a: variable ‘%s’ not found" Ast.string_loc loc name in simplify env expr @@ -196,7 +196,7 @@ and substitute loc env substs = | Ast.SString s -> Buffer.add_string b s | Ast.SVar name -> let expr = - try Ast.StringMap.find name env + try Ast.Env.find name env with Not_found -> failwithf "%a: variable ‘%s’ not found" Ast.string_loc loc name in match simplify env expr with diff --git a/src/main.ml b/src/main.ml index 06af8e5..33d91b6 100644 --- a/src/main.ml +++ b/src/main.ml @@ -77,7 +77,7 @@ let main () = (* assignment *) let name = Str.matched_group 1 arg in let expr = Parse.parse_cli_expr (Str.matched_group 2 arg) in - env := Ast.StringMap.add name expr !env + env := Ast.Env.add name expr !env ) else ( (* target *) diff --git a/src/parser.mly b/src/parser.mly index 3531b08..5a2ce9b 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -49,8 +49,8 @@ file: stmts: | list(stmt) { List.fold_left ( - fun env (name, expr) -> Ast.StringMap.add name expr env - ) Ast.StringMap.empty $1 + fun env (name, expr) -> Ast.Env.add name expr env + ) Ast.Env.empty $1 } ; stmt: -- 1.8.3.1