mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-19 00:15:39 +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
|
||||
|
@ -24,7 +24,7 @@ $ catala test-scope A
|
||||
│ 8 │ definition wrong_definition = 1
|
||||
│ │ ‾
|
||||
│
|
||||
│ Maybe you wanted to write : "." ?
|
||||
│ Maybe you wanted to write: "."?
|
||||
└─
|
||||
#return code 123#
|
||||
```
|
||||
|
@ -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#
|
||||
```
|
||||
|
@ -25,7 +25,7 @@ $ catala Typecheck
|
||||
│ │ ‾‾‾‾‾
|
||||
├─ Article
|
||||
│
|
||||
│ Maybe you wanted to write : "Case1" ?
|
||||
│ Maybe you wanted to write: "Case1"?
|
||||
└─
|
||||
#return code 123#
|
||||
```
|
||||
|
@ -30,7 +30,7 @@ $ catala test-scope A
|
||||
│ 12 │ definitoin i equals 3.
|
||||
│ │ ‾‾‾‾‾‾‾‾‾‾
|
||||
│
|
||||
│ Maybe you wanted to write : "definition" ?
|
||||
│ Maybe you wanted to write: "definition"?
|
||||
└─
|
||||
|
||||
┌─[ERROR (2/2)]─
|
||||
@ -46,7 +46,7 @@ $ catala test-scope A
|
||||
│ 16 │ definition i equal money of (decimal of x)
|
||||
│ │ ‾‾‾‾‾
|
||||
│
|
||||
│ Maybe you wanted to write : "equals" ?
|
||||
│ Maybe you wanted to write: "equals"?
|
||||
└─
|
||||
#return code 123#
|
||||
```
|
||||
|
@ -21,7 +21,7 @@ $ catala test-scope A
|
||||
│ 5 │ output i contents decimal
|
||||
│ │ ‾‾‾‾‾‾‾‾
|
||||
│
|
||||
│ Maybe you wanted to write : "content" ?
|
||||
│ Maybe you wanted to write: "content"?
|
||||
└─
|
||||
#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