diff options
| author | Alasdair Armstrong | 2019-03-15 16:45:53 +0000 |
|---|---|---|
| committer | Alasdair Armstrong | 2019-03-15 16:47:56 +0000 |
| commit | d74ad78a26a92c054b93e4fdce9623d0fdca7edd (patch) | |
| tree | 5b8aaec4a4731fc8741e14ee5da712715d4838af | |
| parent | fadfab23c519c2e7f6205277c879fe99bee89fdb (diff) | |
Interactive: Auto-complete options and add hints
| -rw-r--r-- | opam | 2 | ||||
| -rw-r--r-- | src/isail.ml | 32 |
2 files changed, 32 insertions, 2 deletions
@@ -28,7 +28,7 @@ depends: [ "ocamlbuild" "zarith" "menhir" - "linenoise" + "linenoise" {>= "1.1.0"} "ott" {>= "0.28"} "lem" {>= "2018-12-14"} "linksem" {>= "0.3"} diff --git a/src/isail.ml b/src/isail.ml index f7b4b1d7..3eea268d 100644 --- a/src/isail.ml +++ b/src/isail.ml @@ -552,7 +552,7 @@ let () = fun line_so_far ln_completions -> let line_so_far, last_id = try - let p = Str.search_backward (Str.regexp "[^a-zA-Z0-9_/]") line_so_far (String.length line_so_far - 1) in + let p = Str.search_backward (Str.regexp "[^a-zA-Z0-9_/-]") line_so_far (String.length line_so_far - 1) in Str.string_before line_so_far (p + 1), Str.string_after line_so_far (p + 1) with | Not_found -> "", line_so_far @@ -575,6 +575,11 @@ let () = (line_so_far ^ Filename.concat dirname contents.(i) ^ (if is_dir then Filename.dir_sep else "")) done end + else if cmd = ":option" then + List.map (fun (opt, _, _) -> opt) options + |> List.filter (fun opt -> Str.string_match (Str.regexp_string last_id) opt 0) + |> List.map (fun completion -> line_so_far ^ completion) + |> List.iter (LNoise.add_completion ln_completions) else IdSet.elements !vs_ids |> List.map string_of_id @@ -584,6 +589,31 @@ let () = else () ); + LNoise.set_hints_callback ( + fun line_so_far -> + let hint str = Some (" " ^ str, LNoise.Yellow, false) in + match String.trim line_so_far with + | _ when !Interactive.opt_emacs_mode -> None + | ":load" | ":l" -> hint "<sail file>" + | ":bind" | ":b" -> hint "<id> : <type>" + | ":infer" | ":i" -> hint "<expression>" + | ":type" | ":t" -> hint "<function id>" + | ":let" -> hint "<id> = <expression>" + | ":def" -> hint "<definition>" + | ":prove" -> hint "<constraint>" + | ":assume" -> hint "<constraint>" + | str -> + let args = Str.split (Str.regexp " +") str in + match args with + | [":option"] -> hint "<flag>" + | [":option"; flag] -> + begin match List.find_opt (fun (opt, _, _) -> flag = opt) options with + | Some (_, _, help) -> hint (Str.global_replace (Str.regexp " +") " " help) + | None -> None + end + | _ -> None + ); + (* Read the script file if it is set with the -is option, and excute them *) begin match !opt_interactive_script with |
