| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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 |
|
| 49 |
|
| 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 |
|
| 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 |