| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 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 |
| 31 |
|
| 32 |
|
| 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 |
|
| 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 |
|
| 81 |
; submit_answer : Answer.t -> unit |
| 82 |
|
| 83 |
; isTerminal : bool |
| 84 |
|
| 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 |