Skip to content

Commit 4b2b37e

Browse files
authored
fix export -o lp (ex beautify) (#816)
1 parent efd9e64 commit 4b2b37e

File tree

3 files changed

+70
-29
lines changed

3 files changed

+70
-29
lines changed

src/parsing/pretty.ml

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ let rec term : p_term pp = fun ppf t ->
127127
match ts with
128128
| None -> ()
129129
| Some [||] when !empty_context -> ()
130-
| Some ts -> out ppf "[%a]" (Array.pp func "; ") ts
130+
| Some ts -> out ppf ".[%a]" (Array.pp func "; ") ts
131131
in
132132
match (t.elt, priority) with
133133
| (P_Type , _ ) -> out ppf "TYPE"
@@ -154,9 +154,8 @@ let rec term : p_term pp = fun ppf t ->
154154
out ppf "@[@[<hv2>let @[<2>%a%a%a@] ≔@ %a@ @]in@ %a@]"
155155
ident x params_list xs typ a func t func u
156156
| (P_NLit(i) , _ ) -> out ppf "%i" i
157-
(* We print minimal parentheses, and ignore the [Wrap] constructor. *)
158-
| (P_Wrap(t) , _ ) -> pp priority ppf t
159-
| (P_Expl(t) , _ ) -> out ppf "{@[<hv2>%a@]}" func t
157+
| (P_Wrap(t) , _ ) -> out ppf "(@[<hv2>%a@])" func t
158+
| (P_Expl(t) , _ ) -> out ppf "[@[<hv2>%a@]]" func t
160159
| (_ , _ ) -> out ppf "(@[<hv2>%a@])" func t
161160
in
162161
let rec toplevel ppf t =
@@ -172,9 +171,10 @@ let rec term : p_term pp = fun ppf t ->
172171
toplevel ppf t
173172

174173
and params : p_params pp = fun ppf (ids, t, b) ->
175-
match b with
176-
| false -> out ppf "@[(@,@[<2>%a%a@]@,)@]" param_ids ids typ t
177-
| true -> out ppf "@[{@,@[<2>%a%a@]@,}@]" param_ids ids typ t
174+
if b then out ppf "@[[@,@[<2>%a%a@]@,]@]" param_ids ids typ t
175+
else match t with
176+
| Some t -> out ppf "@[(@,@[<2>%a : %a@]@,)@]" param_ids ids term t
177+
| None -> out ppf "@[@,@[<2>%a@]@,@]" param_ids ids
178178

179179
(* starts with a space if the list is not empty *)
180180
and params_list : p_params list pp = fun ppf ->
@@ -188,9 +188,9 @@ let rule : string -> p_rule pp = fun kw ppf {elt=(l,r);_} ->
188188
out ppf "%s %a ↪ %a" kw term l term r
189189

190190
let inductive : string -> p_inductive pp =
191-
let cons ppf (id,a) = out ppf "| %a : %a" ident id term a in
191+
let cons ppf (id,a) = out ppf "@,| %a : %a" ident id term a in
192192
fun kw ppf {elt=(id,a,cs);_} ->
193-
out ppf "@[<v>%s %a : %a ≔@,%a@]" kw ident id term a (List.pp cons "@,") cs
193+
out ppf "@[<v>%s %a : %a ≔%a@]" kw ident id term a (List.pp cons "") cs
194194

195195
let equiv : (p_term * p_term) pp = fun ppf (l,r) ->
196196
out ppf "%a ≡ %a" term l term r
@@ -245,18 +245,18 @@ let query : p_query pp = fun ppf { elt; _ } ->
245245
match elt with
246246
| P_query_assert(true, a) -> out ppf "assertnot ⊢ %a" assertion a
247247
| P_query_assert(false,a) -> out ppf "assert ⊢ %a" assertion a
248-
| P_query_debug(true ,s) -> out ppf "set debug \"+%s\"" s
249-
| P_query_debug(false,s) -> out ppf "set debug \"-%s\"" s
248+
| P_query_debug(true ,s) -> out ppf "debug \"+%s\"" s
249+
| P_query_debug(false,s) -> out ppf "debug \"-%s\"" s
250250
| P_query_flag(s, b) ->
251-
out ppf "set flag \"%s\" %s" s (if b then "on" else "off")
251+
out ppf "flag \"%s\" %s" s (if b then "on" else "off")
252252
| P_query_infer(t, _) -> out ppf "type %a" term t
253253
| P_query_normalize(t, _) -> out ppf "compute %a" term t
254-
| P_query_prover s -> out ppf "set prover \"%s\"" s
255-
| P_query_prover_timeout n -> out ppf "set prover_timeout %d" n
254+
| P_query_prover s -> out ppf "prover \"%s\"" s
255+
| P_query_prover_timeout n -> out ppf "prover_timeout %d" n
256256
| P_query_print None -> out ppf "print"
257257
| P_query_print(Some qid) -> out ppf "print %a" qident qid
258258
| P_query_proofterm -> out ppf "proofterm"
259-
| P_query_verbose i -> out ppf "set verbose %i" i
259+
| P_query_verbose i -> out ppf "verbose %i" i
260260

261261
let tactic : p_tactic pp = fun ppf { elt; _ } ->
262262
begin match elt with
@@ -273,10 +273,10 @@ let tactic : p_tactic pp = fun ppf { elt; _ } ->
273273
| P_tac_refl -> out ppf "reflexivity"
274274
| P_tac_rewrite(b,p,t) ->
275275
let dir ppf b = if not b then out ppf " left" in
276-
let pat ppf p = out ppf " [%a]" rw_patt p in
276+
let pat ppf p = out ppf " .[%a]" rw_patt p in
277277
out ppf "rewrite%a%a %a" dir b (Option.pp pat) p term t
278-
| P_tac_simpl None -> out ppf "simpl"
279-
| P_tac_simpl (Some qid) -> out ppf "simpl %a" qident qid
278+
| P_tac_simpl None -> out ppf "simplify"
279+
| P_tac_simpl (Some qid) -> out ppf "simplify %a" qident qid
280280
| P_tac_solve -> out ppf "solve"
281281
| P_tac_sym -> out ppf "symmetry"
282282
| P_tac_why3 p ->
@@ -298,7 +298,7 @@ let notation : Sign.notation pp = fun ppf -> function
298298
| _ -> ()
299299

300300
let rec subproof : p_subproof pp = fun ppf sp ->
301-
out ppf "<@[<hv2>@ %a@ @]>" proofsteps sp
301+
out ppf "{@[<hv2>@ %a@ @]}" proofsteps sp
302302

303303
and subproofs : p_subproof list pp = fun ppf spl ->
304304
out ppf "@[<hv>%a@]" (pp_print_list ~pp_sep:pp_print_space subproof) spl
@@ -310,7 +310,7 @@ and proofstep : p_proofstep pp = fun ppf (Tactic (t, spl)) ->
310310
out ppf "@[<hv2>%a@,%a;@]" tactic t subproofs spl
311311

312312
let proof : (p_proof * p_proof_end) pp = fun ppf (p, pe) ->
313-
out ppf "begin@[<hv2>@ %a@ @]%a"
313+
out ppf "begin@ @[<hv2>%a@]@ %a"
314314
(fun ppf -> function
315315
| [block] -> proofsteps ppf block
316316
(* No braces for a single toplevel block *)
@@ -322,11 +322,10 @@ let command : p_command pp = fun ppf { elt; _ } ->
322322
| P_builtin (s, qid) -> out ppf "@[builtin \"%s\"@ ≔ %a@]" s qident qid
323323
| P_inductive (_, _, []) -> assert false (* not possible *)
324324
| P_inductive (ms, xs, i :: il) ->
325-
out ppf "@[<v>@[%a%a@]%a@,%a@,end@]"
326-
modifiers ms
327-
(List.pp params " ") xs
328-
(inductive "inductive") i
329-
(List.pp (inductive "with") "@,") il
325+
let with_ind ppf i = out ppf "@,%a" (inductive "with") i in
326+
out ppf "@[<v>@[%a%a@]%a%a@]"
327+
modifiers ms (List.pp params " ") xs
328+
(inductive "inductive") i (List.pp with_ind "") il
330329
| P_notation (qid, n) -> out ppf "notation %a %a" qident qid notation n
331330
| P_open ps -> out ppf "open %a" (List.pp path " ") ps
332331
| P_query q -> query ppf q
@@ -336,7 +335,9 @@ let command : p_command pp = fun ppf { elt; _ } ->
336335
(List.pp path " ") ps
337336
| P_require_as (p,i) -> out ppf "@[require %a@ as %a@]" path p ident i
338337
| P_rules [] -> assert false (* not possible *)
339-
| P_rules (r :: rs) -> rule "rule" ppf r; List.iter (rule "with" ppf) rs
338+
| P_rules (r :: rs) ->
339+
let with_rule ppf r = out ppf "@.%a" (rule "with") r in
340+
rule "rule" ppf r; List.iter (with_rule ppf) rs
340341
| P_symbol
341342
{ p_sym_mod; p_sym_nam; p_sym_arg; p_sym_typ;
342343
p_sym_trm; p_sym_prf; p_sym_def } ->

tests/export.sh renamed to tests/export_dk.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ do
1919
escape_path|'a b/escape file');; # because dedukti does not accept spaces in module names
2020
262_private_in_lhs);; # because dedukti does not accept protected symbols in rule LHS arguments
2121
273);; # because dedukti SR algorithm fails
22+
file.with.dot|req.file.with.dot);; #FIXME
23+
indind);; #FIXME
2224
*) lp_files="$dir/$f.lp $lp_files";
2325
f=`echo $f | sed -e 's/\//_/g'`;
2426
dk_files="${outdir}_$f.dk $dk_files";
@@ -29,11 +31,11 @@ done
2931
# compile lp files (optional)
3032
compile() {
3133
cd $root
32-
echo compile lp files (optional) ...
34+
echo 'compile lp files (optional) ...'
3335
#$lambdapi check -w -c $lp_files # does not work because of #802
3436
for f in $lp_files
3537
do
36-
echo compile $f ...
38+
echo "compile $f ..."
3739
$lambdapi check -w -v 0 -c $f
3840
done
3941
}
@@ -42,7 +44,7 @@ time compile # can be commented
4244
# translate lp files to dk files
4345
translate() {
4446
cd $root
45-
echo translate lp files ...
47+
echo 'translate lp files ...'
4648
for f in $lp_files
4749
do
4850
f=${f%.lp}

tests/export_lp.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Test lp export
4+
5+
TIMEFORMAT="%E"
6+
root=`pwd`
7+
lambdapi='dune exec -- lambdapi'
8+
9+
outdir=.tmp
10+
#rm -rf $outdir
11+
mkdir -p "$outdir/OK/a b"
12+
cp -f lambdapi.pkg $outdir
13+
14+
# translate lp files
15+
translate() {
16+
cd $root
17+
echo translate lp files ...
18+
for f in OK/*.lp 'OK/a b/escape file.lp'
19+
do
20+
out=$outdir/$f
21+
echo "$f --> $out ..."
22+
$lambdapi export -o lp -w -v 0 "$f" > "$out"
23+
if test $? -ne 0; then echo KO; exit 1; fi
24+
done
25+
}
26+
time translate
27+
28+
# check lp files
29+
check() {
30+
cd $outdir
31+
echo check lp files ...
32+
$lambdapi check -w -v 0 OK/*.lp
33+
if test $? -ne 0; then echo KO; exit 1; fi
34+
}
35+
time check
36+
37+
cd $root
38+
echo OK

0 commit comments

Comments
 (0)