Debian Codegraph @

vernac/debugHook.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 (** Ltac debugger interface; clients should register hooks to interact
12 with their provided interface. *)
13 module Action = struct
14 type t =
15 | StepIn
16 | StepOver
17 | StepOut
18 | Continue
19 | Skip
20 | Interrupt
21 | Help
22 | UpdBpts of ((string * int) * bool) list
23 | Configd
24 | GetStack
25 | GetVars of int
26 | RunCnt of int
27 | RunBreakpoint of string
28 | Command of string
29 | Failed
30 | Ignore (* do nothing, read another command *)
31
32 (* XXX: Could we move this to the CString utility library? *)
33 let possibly_unquote s =
34 if String.length s >= 2 && s.[0] == '"' && s.[String.length s - 1] == '"' then
35 String.sub s 1 (String.length s - 2)
36 else
37 s
38
39 let parse_complex inst : (t, string) result =
40 if 'r' = String.get inst 0 then
41 let arg = String.(trim (sub inst 1 (length inst - 1))) in
42 if arg <> "" then
43 match int_of_string_opt arg with
44 | Some num ->
45 if num < 0 then
46 Error "number must be positive"
47 else
48 Ok (RunCnt num)
49 | None ->
50 Ok (RunBreakpoint (possibly_unquote arg))
51 else
52 Error ("invalid input: " ^ inst)
53 else
54 Error ("invalid input: " ^ inst)
55
56 (* XXX: Should be moved to the clients *)
57 let parse inst : (t, string) result =
58 match inst with
59 | "" -> Ok StepIn
60 | "s" -> Ok Skip
61 | "x" -> Ok Interrupt
62 | "h"| "?" -> Ok Help
63 | _ -> parse_complex inst
64 end
65
66 module Answer = struct
67 type t =
68 | Prompt of Pp.t
69 | Goal of Pp.t
70 | Output of Pp.t
71 | Init
72 | Stack of (string * (string * int list) option) list
73 | Vars of (string * Pp.t) list
74 end
75
76 module Intf = struct
77
78 type t =
79 { read_cmd : unit -> Action.t
80 (** request a debugger command from the client *)
81 ; submit_answer : Answer.t -> unit
82 (** receive a debugger answer from Ltac *)
83 ; isTerminal : bool
84 (** whether the debugger is running as a terminal (non-visual) *)
85 }
86
87 let ltac_debug_ref : t option ref = ref None
88 let set hooks = ltac_debug_ref := Some hooks
89 let get () = !ltac_debug_ref
90
91 end