(* Copyright (C) 2004-2005, HELM Team. * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science * Department, University of Bologna, Italy. * * HELM is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * HELM is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HELM; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, * http://helm.cs.unibo.it/ *) open Printf open CicNotationEnv open CicNotationPt let pp_binder = function | `Lambda -> "lambda" | `Pi -> "Pi" | `Exists -> "exists" | `Forall -> "forall" let pp_literal l = sprintf "literal(%s)" (match l with | `Symbol s | `Keyword s | `Number s -> s) let rec pp_term = function | AttributedTerm (_, term) -> pp_term term | Appl terms -> sprintf "(%s)" (String.concat " " (List.map pp_term terms)) | Binder (`Forall, (Ident ("_", None), typ), body) | Binder (`Pi, (Ident ("_", None), typ), body) -> sprintf "(%s \\to %s)" (match typ with None -> "?" | Some typ -> pp_term typ) (pp_term body) | Binder (kind, var, body) -> sprintf "\\%s %s.%s" (pp_binder kind) (pp_capture_variable var) (pp_term body) | Case (term, indtype, typ, patterns) -> sprintf "%smatch %s with %s" (match typ with None -> "" | Some t -> sprintf "<%s>" (pp_term t)) (pp_term term) (pp_patterns patterns) | LetIn (var, t1, t2) -> sprintf "let %s = %s in %s" (pp_capture_variable var) (pp_term t1) (pp_term t2) | LetRec (kind, definitions, term) -> sprintf "let %s %s in %s" (match kind with `Inductive -> "rec" | `CoInductive -> "corec") (String.concat " and " (List.map (fun (var, body, _) -> sprintf "%s = %s" (pp_capture_variable var) (pp_term body)) definitions)) (pp_term term) | Ident (name, Some []) | Ident (name, None) | Uri (name, Some []) | Uri (name, None) -> name | Ident (name, Some substs) | Uri (name, Some substs) -> sprintf "%s \\subst [%s]" name (pp_substs substs) | Implicit -> "?" | Meta (index, substs) -> sprintf "%d[%s]" index (String.concat "; " (List.map (function None -> "_" | Some term -> pp_term term) substs)) | Num (num, _) -> num | Sort `Set -> "Set" | Sort `Prop -> "Prop" | Sort `Type -> "Type" | Sort `CProp -> "CProp" | Symbol (name, _) -> name | UserInput -> "" | Literal l -> pp_literal l | Layout l -> pp_layout l | Magic m -> pp_magic m | Variable v -> pp_variable v and pp_subst (name, term) = sprintf "%s \\Assign %s" name (pp_term term) and pp_substs substs = String.concat "; " (List.map pp_subst substs) and pp_pattern ((head, vars), term) = sprintf "%s \\Rightarrow %s" (match vars with | [] -> head | _ -> sprintf "(%s %s)" head (String.concat " " (List.map pp_capture_variable vars))) (pp_term term) and pp_patterns patterns = sprintf "[%s]" (String.concat " | " (List.map pp_pattern patterns)) and pp_capture_variable = function | term, None -> pp_term term | term, Some typ -> "(" ^ pp_term term ^ ": " ^ pp_term typ ^ ")" and pp_layout = function | Sub (t1, t2) -> sprintf "%s \\SUB %s" (pp_term t1) (pp_term t2) | Sup (t1, t2) -> sprintf "%s \\SUP %s" (pp_term t1) (pp_term t2) | Below (t1, t2) -> sprintf "%s \\BELOW %s" (pp_term t1) (pp_term t2) | Above (t1, t2) -> sprintf "%s \\ABOVE %s" (pp_term t1) (pp_term t2) | Over (t1, t2) -> sprintf "[%s \\OVER %s]" (pp_term t1) (pp_term t2) | Atop (t1, t2) -> sprintf "[%s \\ATOP %s]" (pp_term t1) (pp_term t2) | Frac (t1, t2) -> sprintf "\\FRAC %s %s" (pp_term t1) (pp_term t2) | Sqrt t -> sprintf "\\SQRT %s" (pp_term t) | Root (arg, index) -> sprintf "\\ROOT %s \\OF %s" (pp_term index) (pp_term arg) | Break -> "\\BREAK" | Box (H, terms) -> sprintf "\\HBOX [%s]" (String.concat " " (List.map pp_term terms)) | Box (V, terms) -> sprintf "\\VBOX [%s]" (String.concat " " (List.map pp_term terms)) and pp_magic = function | List0 (t, sep_opt) -> sprintf "\\LIST0 %s%s" (pp_term t) (pp_sep_opt sep_opt) | List1 (t, sep_opt) -> sprintf "\\LIST1 %s%s" (pp_term t) (pp_sep_opt sep_opt) | Opt t -> sprintf "\\OPT %s" (pp_term t) | _ -> failwith "magic not implemented" and pp_sep_opt = function | None -> "" | Some sep -> sprintf "\\SEP %s" (pp_literal sep) and pp_variable = function | NumVar s -> "\\NUM " ^ s | IdentVar s -> "\\IDENT " ^ s | TermVar s -> "\\TERM " ^ s | Ascription (t, n) -> sprintf "[%s \\AS %s]" (pp_term t) n | FreshVar n -> "\\FRESH " ^ n let rec pp_value = function | TermValue t -> sprintf "$%s$" (pp_term t) | StringValue s -> sprintf "\"%s\"" s | NumValue n -> n | OptValue (Some v) -> "Some " ^ pp_value v | OptValue None -> "None" | ListValue l -> sprintf "[%s]" (String.concat "; " (List.map pp_value l)) let rec pp_value_type = function | TermType -> "Term" | StringType -> "String" | NumType -> "Number" | OptType t -> "Maybe " ^ pp_value_type t | ListType l -> "List " ^ pp_value_type l let pp_env env = String.concat "; " (List.map (fun (name, (ty, value)) -> sprintf "%s : %s = %s" name (pp_value_type ty) (pp_value value)) env)