| `Exists -> "exists"
| `Forall -> "forall"
-let pp_literal = function
+(* let pp_literal = function (* debugging version *)
| `Symbol s -> sprintf "symbol(%s)" s
| `Keyword s -> sprintf "keyword(%s)" s
- | `Number s -> sprintf "number(%s)" s
-
-let rec pp_term = function
- | AttributedTerm (`Href _, term) when print_attributes ->
- sprintf "#[%s]" (pp_term term)
- | AttributedTerm (_, term) when print_attributes ->
- sprintf "@[%s]" (pp_term term)
- | 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)
- | Cast (t1, t2) -> sprintf "(%s: %s)" (pp_term t1) (pp_term t2)
- | 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
+ | `Number s -> sprintf "number(%s)" s *)
+
+let pp_literal = function
+ | `Symbol s
+ | `Keyword s
+ | `Number s -> s
+
+let rec pp_term ?(pp_parens = true) t =
+ let t_pp =
+ match t with
+(* | AttributedTerm (`Href _, term) when print_attributes ->
+ sprintf "#[%s]" (pp_term term)
+ | AttributedTerm (_, term) when print_attributes ->
+ sprintf "@[%s]" (pp_term term) *)
+ | AttributedTerm (`Raw (text, None), _) -> text
+ | AttributedTerm (`Raw (text, Some `Ast), _) -> sprintf "@{%s}" text
+ | AttributedTerm (`Raw (text, Some `Meta), _) -> sprintf "${%s}" text
+ | AttributedTerm (_, term) -> pp_term ~pp_parens:false 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)
+ | Cast (t1, t2) -> sprintf "(%s: %s)" (pp_term t1) (pp_term t2)
+ | 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 t -> pp_term t) 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
+ in
+ if pp_parens then sprintf "(%s)" t_pp
+ else t_pp
and pp_subst (name, term) = sprintf "%s \\Assign %s" name (pp_term term)
and pp_substs substs = String.concat "; " (List.map pp_subst substs)
sprintf "\\GROUP [%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)
- | Fold (k, p_base, names, p_rec) ->
+ | 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)
+ | Fold (kind, p_base, names, p_rec) ->
let acc = match names with acc :: _ -> acc | _ -> assert false in
- sprintf "\\FOLD %s \\[%s\\] \\LAMBDA %s \\[%s\\]"
- (pp_fold_kind k) (pp_term p_base) acc (pp_term p_rec)
+ sprintf "fold %s %s rec %s %s"
+ (pp_fold_kind kind) (pp_term p_base) acc (pp_term p_rec)
| Default (p_some, p_none) ->
- sprintf "\\DEFAULT \\[%s\\] \\[%s\\]" (pp_term p_some) (pp_term p_none)
+ sprintf "default %s %s" (pp_term p_some) (pp_term p_none)
| If (p_test, p_true, p_false) ->
- sprintf "\\IF \\[%s\\] \\[%s\\] \\[%s\\]"
+ sprintf "if %s then %s else %s"
(pp_term p_test) (pp_term p_true) (pp_term p_false)
- | Fail -> "\\FAIL"
+ | Fail -> "fail"
and pp_fold_kind = function
| `Left -> "left"
and pp_sep_opt = function
| None -> ""
- | Some sep -> sprintf "\\SEP %s" (pp_literal sep)
+ | 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
+ | NumVar s -> "number " ^ s
+ | IdentVar s -> "ident " ^ s
+ | TermVar s -> "term " ^ s
+ | Ascription (t, n) -> assert false
+ | FreshVar n -> "fresh " ^ n
+
+let pp_term t = pp_term ~pp_parens:false t
let rec pp_value = function
| TermValue t -> sprintf "$%s$" (pp_term t)
"record " ^ name ^ " " ^ pp_params params ^ " \\def {" ^
pp_fields fields ^ "}"
+let pp_argument_pattern = function
+ | CicNotationPt.IdentArg (eta_depth, name) ->
+ let eta_buf = Buffer.create 5 in
+ for i = 1 to eta_depth do
+ Buffer.add_string eta_buf "\\eta."
+ done;
+ sprintf "%s%s" (Buffer.contents eta_buf) name
+
+let rec pp_cic_appl_pattern = function
+ | CicNotationPt.UriPattern uri -> UriManager.string_of_uri uri
+ | CicNotationPt.VarPattern name -> name
+ | CicNotationPt.ImplicitPattern -> "_"
+ | CicNotationPt.ApplPattern aps ->
+ sprintf "(%s)" (String.concat " " (List.map pp_cic_appl_pattern aps))
+
+let pp_l1_pattern = CicNotationPp.pp_term
+let pp_l2_pattern = CicNotationPp.pp_term
+
+let pp_associativity = function
+ | Some Gramext.LeftA -> "left associative "
+ | Some Gramext.RightA -> "right associative "
+ | Some Gramext.NonA -> "non associative "
+ | None -> ""
+
+let pp_precedence = function
+ | Some i -> sprintf "with precedence %d " i
+ | None -> ""
+
let pp_command = function
| Include (_,path) -> "include " ^ path
| Qed _ -> "qed"
| Default (_,what,uris) ->
sprintf "default \"%s\" %s" what
(String.concat " " (List.map UriManager.string_of_uri uris))
+ | Interpretation (_, dsc, (symbol, arg_patterns), cic_appl_pattern) ->
+ sprintf "interpretation \"%s\" '%s %s = %s"
+ dsc symbol
+ (String.concat " " (List.map pp_argument_pattern arg_patterns))
+ (pp_cic_appl_pattern cic_appl_pattern)
+ | Notation (_, l1_pattern, assoc, prec, l2_pattern) ->
+ sprintf "notation \"%s\" %s%sfor %s"
+ (pp_l1_pattern l1_pattern)
+ (pp_associativity assoc)
+ (pp_precedence prec)
+ (pp_l2_pattern l2_pattern)
+ | Render _
+ | Dump _ -> assert false (* ZACK: debugging *)
let rec pp_tactical = function
| Tactic (_, tac) -> pp_tactic tac
| Qed _ -> "qed"
| Drop _ -> "drop"
| Coercion (_,term) -> sprintf "coercion %s" (CicPp.ppterm term)
- | Set (_, _, _)
- | Alias (_,_)
- | Default (_,_,_)
- | Obj (_,_) -> assert false (* not implemented *)
+ | Set _
+ | Alias _
+ | Default _
+ | Render _
+ | Dump _
+ | Interpretation _
+ | Notation _
+ | Obj _ -> assert false (* not implemented *)
+