Better errors & add colors
This commit is contained in:
parent
fc846d2233
commit
0085a91251
10
affichage.ml
10
affichage.ml
@ -35,8 +35,14 @@ let print_goal ((_, ty, c) : goal) : unit =
|
|||||||
let rec print_hyps (c : context) : unit = match c with
|
let rec print_hyps (c : context) : unit = match c with
|
||||||
[] -> ()
|
[] -> ()
|
||||||
| (id, _, ty)::q -> print_string (id^" : "^(string_of_ty ty)^"\n"); print_hyps q
|
| (id, _, ty)::q -> print_string (id^" : "^(string_of_ty ty)^"\n"); print_hyps q
|
||||||
in print_hyps c;
|
in
|
||||||
|
print_string "\027[1m";
|
||||||
|
print_hyps c;
|
||||||
print_ty ty;
|
print_ty ty;
|
||||||
print_string "\n==========\n"
|
print_string "\n==========\027[0m\n"
|
||||||
|
|
||||||
let affiche_val _ = print_string "TODO"
|
let affiche_val _ = print_string "TODO"
|
||||||
|
|
||||||
|
let print_error (error_type : string) (details : string) =
|
||||||
|
output_string stderr ("\027[1;31mError:\027[0m \027[34m"^error_type^"\027[0m "^details^"\n");
|
||||||
|
flush stderr
|
10
main.ml
10
main.ml
@ -50,7 +50,7 @@ let rec interactive ((g, gs) : proof) : proof =
|
|||||||
in
|
in
|
||||||
|
|
||||||
let _ = match g with
|
let _ = match g with
|
||||||
None -> print_string "\nNo more goals.\n"
|
None -> print_string "\n\027[1mNo more goals.\027[0m\n"
|
||||||
| Some g' -> print_newline (); print_goal g'
|
| Some g' -> print_newline (); print_goal g'
|
||||||
in
|
in
|
||||||
|
|
||||||
@ -60,13 +60,13 @@ let rec interactive ((g, gs) : proof) : proof =
|
|||||||
| Tact t -> apply_tactic (g, gs) t |> interactive
|
| Tact t -> apply_tactic (g, gs) t |> interactive
|
||||||
with
|
with
|
||||||
Parser.Error ->
|
Parser.Error ->
|
||||||
print_string "Invalid input.\n";
|
print_error "Invalid input" "";
|
||||||
interactive (g, gs)
|
interactive (g, gs)
|
||||||
| End_of_file ->
|
| End_of_file ->
|
||||||
print_string "Bye!\n";
|
print_string "Bye!\n";
|
||||||
(g, gs)
|
(g, gs)
|
||||||
| TacticFailed ->
|
| TacticFailed arg ->
|
||||||
print_string "Tactic failed.\n";
|
print_error "Tactic failed" arg;
|
||||||
interactive (g, gs)
|
interactive (g, gs)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ let recupere_entree () =
|
|||||||
else if !reduce
|
else if !reduce
|
||||||
then Reduce (parse_channel_lam where_from)
|
then Reduce (parse_channel_lam where_from)
|
||||||
else Simple (parse_channel_lam where_from)
|
else Simple (parse_channel_lam where_from)
|
||||||
with e -> (Printf.printf "problème de saisie\n"; raise e)
|
with e -> (print_error "problème de saisie" ""; raise e)
|
||||||
|
|
||||||
(* la fonction principale *)
|
(* la fonction principale *)
|
||||||
let run () =
|
let run () =
|
||||||
|
28
proof.ml
28
proof.ml
@ -1,7 +1,7 @@
|
|||||||
open Lam
|
open Lam
|
||||||
open Types
|
open Types
|
||||||
|
|
||||||
exception TacticFailed
|
exception TacticFailed of string
|
||||||
|
|
||||||
type hlam = (* hollow lam *)
|
type hlam = (* hollow lam *)
|
||||||
HFun of (id * Types.ty) * hlam
|
HFun of (id * Types.ty) * hlam
|
||||||
@ -40,7 +40,7 @@ let proof_is_over ((g, _) : proof) : bool =
|
|||||||
let fill (hole : hlam) (e : hlam) : unit =
|
let fill (hole : hlam) (e : hlam) : unit =
|
||||||
match hole with
|
match hole with
|
||||||
Ref h -> h := e
|
Ref h -> h := e
|
||||||
| _ -> failwith "not fillable"
|
| _ -> raise (TacticFailed "not fillable")
|
||||||
|
|
||||||
let rec hlam_of_lam : lam -> hlam = function
|
let rec hlam_of_lam : lam -> hlam = function
|
||||||
Fun ((x, t), e) ->
|
Fun ((x, t), e) ->
|
||||||
@ -68,7 +68,7 @@ let rec lam_of_hlam : hlam -> lam = function
|
|||||||
let e = lam_of_hlam e in
|
let e = lam_of_hlam e in
|
||||||
Exf (e, t)
|
Exf (e, t)
|
||||||
| Ref e_ref -> lam_of_hlam !e_ref
|
| Ref e_ref -> lam_of_hlam !e_ref
|
||||||
| Hole -> failwith "can not translate unclosed terms"
|
| Hole -> raise (TacticFailed "can not translate unclosed terms")
|
||||||
|
|
||||||
|
|
||||||
let rec get_term_by_id (hyp : id) : context -> hlam option =
|
let rec get_term_by_id (hyp : id) : context -> hlam option =
|
||||||
@ -90,24 +90,24 @@ let next_goal (gs : goal list) : (goal option * goal list) =
|
|||||||
|
|
||||||
let tact_exact_term ((g, gs) : proof) (e : lam) : proof =
|
let tact_exact_term ((g, gs) : proof) (e : lam) : proof =
|
||||||
match g with
|
match g with
|
||||||
None -> failwith "no current goal"
|
None -> raise (TacticFailed "no current goal")
|
||||||
| Some (h, _, _) ->
|
| Some (h, _, _) ->
|
||||||
fill h (hlam_of_lam e);
|
fill h (hlam_of_lam e);
|
||||||
next_goal gs
|
next_goal gs
|
||||||
|
|
||||||
let tact_exact_proof ((g, gs) : proof) (hyp : id) : proof =
|
let tact_exact_proof ((g, gs) : proof) (hyp : id) : proof =
|
||||||
match g with
|
match g with
|
||||||
None -> failwith "no current goal"
|
None -> raise (TacticFailed "no current goal")
|
||||||
| Some (h, _, cs) ->
|
| Some (h, _, cs) ->
|
||||||
match get_term_by_id hyp cs with
|
match get_term_by_id hyp cs with
|
||||||
Some h' ->
|
Some h' ->
|
||||||
fill h h';
|
fill h h';
|
||||||
next_goal gs
|
next_goal gs
|
||||||
| None -> raise TacticFailed
|
| None -> raise (TacticFailed "")
|
||||||
|
|
||||||
let tact_assumption ((g, gs) : proof) : proof =
|
let tact_assumption ((g, gs) : proof) : proof =
|
||||||
match g with
|
match g with
|
||||||
None -> failwith "no current goal"
|
None -> raise (TacticFailed "no current goal")
|
||||||
| Some (h, goal_ty, cs) ->
|
| Some (h, goal_ty, cs) ->
|
||||||
match get_term_by_type goal_ty cs with
|
match get_term_by_type goal_ty cs with
|
||||||
None -> (* failwith "assumption failed" *) (g, gs)
|
None -> (* failwith "assumption failed" *) (g, gs)
|
||||||
@ -117,7 +117,7 @@ let tact_assumption ((g, gs) : proof) : proof =
|
|||||||
|
|
||||||
let tact_intro ((g, gs) : proof) : proof =
|
let tact_intro ((g, gs) : proof) : proof =
|
||||||
match g with
|
match g with
|
||||||
None -> failwith "no current goal"
|
None -> raise (TacticFailed "no current goal")
|
||||||
| Some (h, goal_ty, cs) ->
|
| Some (h, goal_ty, cs) ->
|
||||||
match goal_ty with
|
match goal_ty with
|
||||||
Arr (t1, t2) ->
|
Arr (t1, t2) ->
|
||||||
@ -127,11 +127,11 @@ let tact_intro ((g, gs) : proof) : proof =
|
|||||||
fill h (HFun ((var_id, t1), new_h));
|
fill h (HFun ((var_id, t1), new_h));
|
||||||
Some (new_h, t2, cs), gs
|
Some (new_h, t2, cs), gs
|
||||||
| _ -> (* failwith "expected function" *) (* (g, gs) *)
|
| _ -> (* failwith "expected function" *) (* (g, gs) *)
|
||||||
raise TacticFailed
|
raise (TacticFailed "expected function")
|
||||||
|
|
||||||
let tact_cut ((g, gs) : proof) (new_t : Types.ty) : proof =
|
let tact_cut ((g, gs) : proof) (new_t : Types.ty) : proof =
|
||||||
match g with
|
match g with
|
||||||
None -> failwith "no current goal"
|
None -> raise (TacticFailed "no current goal")
|
||||||
| Some (h, goal_ty, cs) ->
|
| Some (h, goal_ty, cs) ->
|
||||||
(* subgoal 2 : new_t -> goal_ty *)
|
(* subgoal 2 : new_t -> goal_ty *)
|
||||||
let arrow_h = Ref (ref Hole) in
|
let arrow_h = Ref (ref Hole) in
|
||||||
@ -144,12 +144,12 @@ let tact_cut ((g, gs) : proof) (new_t : Types.ty) : proof =
|
|||||||
|
|
||||||
let tact_apply ((g, gs) : proof) (hyp_id : id) : proof =
|
let tact_apply ((g, gs) : proof) (hyp_id : id) : proof =
|
||||||
let rec get_hyp = function
|
let rec get_hyp = function
|
||||||
[] -> failwith "no such hypothesis in context"
|
[] -> raise (TacticFailed "no such hypothesis in context")
|
||||||
| (hyp_id', h', t') :: _ when hyp_id = hyp_id' -> (h', t')
|
| (hyp_id', h', t') :: _ when hyp_id = hyp_id' -> (h', t')
|
||||||
| _ :: cs -> get_hyp cs
|
| _ :: cs -> get_hyp cs
|
||||||
in
|
in
|
||||||
match g with
|
match g with
|
||||||
None -> failwith "no current goal"
|
None -> raise (TacticFailed "no current goal")
|
||||||
| Some (h, goal_ty, cs) ->
|
| Some (h, goal_ty, cs) ->
|
||||||
let h', t' = get_hyp cs in
|
let h', t' = get_hyp cs in
|
||||||
match t' with
|
match t' with
|
||||||
@ -165,7 +165,7 @@ let tact_intros : proof -> proof =
|
|||||||
try
|
try
|
||||||
let p = tact_intro p in
|
let p = tact_intro p in
|
||||||
push p
|
push p
|
||||||
with TacticFailed -> p
|
with TacticFailed _ -> p
|
||||||
in push
|
in push
|
||||||
|
|
||||||
let apply_tactic (p : proof) (t : tactic) : proof =
|
let apply_tactic (p : proof) (t : tactic) : proof =
|
||||||
@ -181,4 +181,4 @@ let apply_tactic (p : proof) (t : tactic) : proof =
|
|||||||
|
|
||||||
let tact_try (p : proof) (t : tactic) : proof =
|
let tact_try (p : proof) (t : tactic) : proof =
|
||||||
try apply_tactic p t
|
try apply_tactic p t
|
||||||
with TacticFailed -> p
|
with TacticFailed _ -> p
|
||||||
|
Loading…
Reference in New Issue
Block a user