Debian Codegraph @

proofs/goal_select.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 (* spiwack: I'm choosing, for now, to have [goal_selector] be a
12 different type than [goal_reference] mostly because if it makes sense
13 to print a goal that is out of focus (or already solved) it doesn't
14 make sense to apply a tactic to it. Hence it the types may look very
15 similar, they do not seem to mean the same thing. *)
16 type t =
17 | SelectAlreadyFocused
18 | SelectList of Proofview.goal_range_selector list
19 | SelectAll
20
21 let select_nth n = SelectList [NthSelector n]
22
23 let pr_id_selector id =
24 Pp.(str "[" ++ Libnames.pr_qualid id ++ str "]")
25
26 let pr_range_selector = let open Proofview in function
27 | NthSelector i -> Pp.int i
28 | RangeSelector (i, j) -> Pp.(int i ++ str "-" ++ int j)
29 | IdSelector id -> pr_id_selector id
30
31 let pr_goal_selector = let open Pp in function
32 | SelectAlreadyFocused -> str "!"
33 | SelectAll -> str "all"
34 | SelectList l -> prlist_with_sep pr_comma pr_range_selector l
35
36 let parse_goal_selector = function
37 | "!" -> SelectAlreadyFocused
38 | "all" -> SelectAll
39 | i ->
40 let err_msg = "The default selector must be \"all\", \"!\" or a natural number." in
41 begin try
42 let i = int_of_string i in
43 if i < 0 then CErrors.user_err Pp.(str err_msg);
44 select_nth i
45 with Failure _ -> CErrors.user_err Pp.(str err_msg)
46 end
47
48 (* Default goal selector: selector chosen when a tactic is applied
49 without an explicit selector. *)
50 let { Goptions.get = get_default_goal_selector } =
51 Goptions.declare_interpreted_string_option_and_ref
52 parse_goal_selector
53 (fun v -> Pp.string_of_ppcmds @@ pr_goal_selector v)
54 ~key:["Default";"Goal";"Selector"]
55 ~value:(select_nth 1)
56 ()
57
58 (* Select a subset of the goals *)
59 let tclSELECT ?nosuchgoal g tac = match g with
60 | SelectList [NthSelector i] -> Proofview.tclFOCUS ?nosuchgoal i i tac
61 | SelectList [IdSelector id] -> Proofview.tclFOCUSID ?nosuchgoal id tac
62 | SelectList l -> Proofview.tclFOCUSSELECTORLIST ?nosuchgoal l tac
63 | SelectAll -> tac
64 | SelectAlreadyFocused ->
65 let open Proofview.Notations in
66 Proofview.numgoals >>= fun n ->
67 if n == 1 then tac
68 else
69 let e = CErrors.UserError
70 Pp.(str "Expected a single focused goal but " ++
71 int n ++ str " goals are focused.")
72 in
73 let info = Exninfo.reify () in
74 Proofview.tclZERO ~info e