| NSkip of loc
| NFocus of loc * int list
| NUnfocus of loc
+ | NTry of loc * ntactic
+ | NAssumption of loc
type ('term, 'lazy_term, 'reduction, 'ident) tactic =
(* Higher order tactics (i.e. tacticals) *)
(** To be increased each time the command type below changes, used for "safe"
* marshalling *)
-let magic = 23
+let magic = 24
type ('term,'obj) command =
| Index of loc * 'term option (* key *) * UriManager.uri (* value *)
| `Auto params -> pp_auto_params ~term_pp params
;;
-let pp_ntactic ~map_unicode_to_tex = function
+let rec pp_ntactic ~map_unicode_to_tex = function
| NApply (_,t) -> "napply " ^ CicNotationPp.pp_term t
| NCases (_,what,where) -> "ncases " ^ CicNotationPp.pp_term what ^
assert false ^ " " ^ assert false
(String.concat " " (List.map string_of_int l))
| NUnfocus _ -> "##unfocus"
| NSkip _ -> "##skip"
+ | NTry (_,tac) -> "ntry (" ^ pp_ntactic ~map_unicode_to_tex tac ^ ")"
+ | NAssumption _ -> "nassumption"
;;
let rec pp_tactic ~map_unicode_to_tex ~term_pp ~lazy_term_pp =
| GrafiteAst.Merge _ -> NTactics.merge_tac
;;
-let eval_ng_tac (text, prefix_len, tac) =
+let rec eval_ng_tac (text, prefix_len, tac) =
match tac with
| GrafiteAst.NApply (_loc, t) -> NTactics.apply_tac (text,prefix_len,t)
| GrafiteAst.NAssert (_loc, seqs) ->
| GrafiteAst.NSkip _ -> NTactics.skip_tac
| GrafiteAst.NUnfocus _ -> NTactics.unfocus_tac
| GrafiteAst.NWildcard _ -> NTactics.wildcard_tac
+ | GrafiteAst.NTry (_,tac) -> NTactics.try_tac
+ (eval_ng_tac (text, prefix_len, tac))
+ | GrafiteAst.NAssumption _ -> NTactics.assumption_tac
;;
let subst_metasenv_and_fix_names s =
G.NLetIn (loc,where,t,name)
| kind = nreduction_kind; p = pattern_spec ->
G.NReduce (loc, kind, p)
- | IDENT "nrewrite"; dir = direction; what = tactic_term ; where = pattern_spec ->
+ | IDENT "nrewrite"; dir = direction; what = tactic_term ; where = pattern_spec ->
G.NRewrite (loc, dir, what, where)
+ | IDENT "ntry"; LPAREN ; tac = SELF ; RPAREN -> G.NTry (loc,tac)
+ | IDENT "nassumption" -> G.NAssumption loc
| SYMBOL "#"; n=IDENT -> G.NIntro (loc,n)
| SYMBOL "#"; SYMBOL "_" -> G.NIntro (loc,"_")
| SYMBOL "*" -> G.NCase1 (loc,"_")
let atomic_tac htac = distribute_tac (exec htac) ;;
+let try_tac tac status =
+ try
+ tac status
+ with NTacStatus.Error _ ->
+ status
+;;
+
+let first_tac tacl status =
+ let res = HExtlib.list_findopt
+ (fun tac _ ->
+ try Some (tac status) with
+ NTacStatus.Error _ -> None) tacl
+ in
+ match res with
+ | None -> raise (NTacStatus.Error (lazy("No tactic left")))
+ | Some x -> x
+;;
+
let exact_tac t = distribute_tac (fun status goal ->
let goalty = get_goalty status goal in
let status, t = disambiguate status t (Some goalty) (ctx_of goalty) in
instantiate status goal t)
;;
+let assumption status goal =
+ let gty = get_goalty status goal in
+ let context = ctx_of gty in
+ let (htac:NTacStatus.tactic) =
+ first_tac (List.map
+ (fun (name,_) ->
+ exact_tac ("",0,(Ast.Ident (name,None))))
+ context)
+ in
+ exec htac status goal
+;;
+
+let assumption_tac =
+ distribute_tac assumption
+;;
+
let find_in_context name context =
let rec aux acc = function
| [] -> raise Not_found
val focus_tac: int list -> NTacStatus.tactic
val unfocus_tac: NTacStatus.tactic
val skip_tac: NTacStatus.tactic
+val try_tac: NTacStatus.tactic -> NTacStatus.tactic
val distribute_tac: NTacStatus.lowtactic -> NTacStatus.tactic
val block_tac: NTacStatus.tactic list -> NTacStatus.tactic
val apply_tac: NTacStatus.tactic_term -> NTacStatus.tactic
+val assumption_tac: NTacStatus.tactic
val change_tac:
where:NTacStatus.tactic_pattern -> with_what:NTacStatus.tactic_term ->
NTacStatus.tactic