mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
Refactor and improve suggestions' pretty-printing
This commit is contained in:
parent
441dd54ec3
commit
c26d3fdf4a
@ -77,13 +77,25 @@ let sorted_candidates ?(max_elements = 5) suggs given =
|
||||
in
|
||||
List.concat candidates |> sub [] max_elements
|
||||
|
||||
let format (ppf : Format.formatter) (suggestions_list : string list) =
|
||||
match suggestions_list with
|
||||
let format ppf suggs =
|
||||
let open Format in
|
||||
let pp_elt elt = fprintf ppf "@{<yellow>\"%s\"@}" elt in
|
||||
let rec loop = function
|
||||
| [] -> assert false
|
||||
| [h] ->
|
||||
pp_elt h;
|
||||
pp_print_string ppf "?"
|
||||
| [h; t] ->
|
||||
pp_elt h;
|
||||
fprintf ppf "@ or@ ";
|
||||
loop [t]
|
||||
| h :: t ->
|
||||
pp_elt h;
|
||||
fprintf ppf ",@ ";
|
||||
loop t
|
||||
in
|
||||
match suggs with
|
||||
| [] -> ()
|
||||
| _ :: _ ->
|
||||
Format.pp_print_string ppf "Maybe you wanted to write : ";
|
||||
Format.pp_print_list
|
||||
~pp_sep:(fun ppf () -> Format.fprintf ppf ",@ or ")
|
||||
(fun ppf string -> Format.fprintf ppf "@{<yellow>\"%s\"@}" string)
|
||||
ppf suggestions_list;
|
||||
Format.pp_print_string ppf " ?"
|
||||
| suggs ->
|
||||
pp_print_string ppf "Maybe you wanted to write: ";
|
||||
loop suggs
|
||||
|
@ -50,8 +50,8 @@ $ catala test-scope A
|
||||
│ │ ‾
|
||||
├─ Article
|
||||
│
|
||||
│ Maybe you wanted to write : "field0", or "field2", or "field10",
|
||||
│ or "field1", or "field3" ?
|
||||
│ Maybe you wanted to write: "field0", "field2", "field10", "field1" or
|
||||
│ "field3"?
|
||||
└─
|
||||
#return code 123#
|
||||
```
|
||||
|
@ -29,7 +29,7 @@ $ catala test-scope A
|
||||
│ │ ‾‾‾‾‾
|
||||
├─ Article
|
||||
│
|
||||
│ Maybe you wanted to write : "Case1", or "Case2" ?
|
||||
│ Maybe you wanted to write: "Case1" or "Case2"?
|
||||
└─
|
||||
#return code 123#
|
||||
```
|
||||
|
@ -31,7 +31,7 @@ $ catala dcalc -s Titi
|
||||
│ 2 │ declaration scope Toto:
|
||||
│ │ ‾‾‾‾
|
||||
│
|
||||
│ Maybe you wanted to write : "bar", or "baz", or "foo" ?
|
||||
│ Maybe you wanted to write: "bar", "baz" or "foo"?
|
||||
└─
|
||||
#return code 123#
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user