Skip to content

Commit 7bba6c9

Browse files
committed
Get parentheses in vaguely the right places
1 parent bc3d6d7 commit 7bba6c9

File tree

8 files changed

+81163
-77503
lines changed

8 files changed

+81163
-77503
lines changed

imlformat/iml-prettier.ts

Lines changed: 354 additions & 126 deletions
Large diffs are not rendered by default.

imlformat/iml2json.bc.js

Lines changed: 75629 additions & 75615 deletions
Large diffs are not rendered by default.

imlformat/test/basic.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1+
12
import { expect, test } from '@jest/globals';
23

34
import { format } from "../imlformat.format";
45

6+
test("constants", () => {
7+
format(`
8+
let a = 1
9+
let b = (- 1)
10+
let c = 1.0
11+
let d = (- 1.0)
12+
let e = "abc"
13+
`).then(x =>
14+
expect(x).toEqual(`\
15+
let a = 1
16+
17+
let b = -1
18+
19+
let c = 1.0
20+
21+
let d = -1.0
22+
23+
let e = "abc"`))
24+
})
25+
26+
527
test("function", () => {
628
format(`
729
let
@@ -21,7 +43,7 @@ theorem
2143
= ((f x ) >
2244
x)
2345
`).then(x =>
24-
expect(x).toEqual(`theorem f_gt x = (f x) > x`))
46+
expect(x).toEqual(`theorem f_gt x = f x > x`))
2547
})
2648

2749
test("eval", () => {
@@ -64,4 +86,9 @@ test("directive", () => {
6486
"def";;
6587
`).then(x =>
6688
expect(x).toEqual(`#somedirective "def";;`))
89+
})
90+
91+
test("operator precedence", () => {
92+
format(`let f x y = ((x - 1) * (y + 1)) + 1`)
93+
.then(x => expect(x).toEqual(`let f x y = (x - 1) * (y + 1) + 1`))
6794
})

imlformat/test/decomp.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { expect, test } from '@jest/globals';
2+
3+
import { format } from "../imlformat.format";
4+
5+
test("decomp 1", () => {
6+
format(`
7+
let g x =
8+
if x > 22 then 9
9+
else 100 + x
10+
11+
let f x =
12+
if x > 99 then
13+
100
14+
else if x < 70 && x > 23
15+
then 89 + x
16+
else if x > 20
17+
then g x + 20
18+
else if x > -2 then
19+
103
20+
else 99
21+
[@@decomp top ()]
22+
`).then(x =>
23+
expect(x).toEqual(`\
24+
let g x = if x > 22 then 9 else 100 + x
25+
26+
let f x =
27+
if
28+
x > 99
29+
then
30+
100
31+
else
32+
if
33+
x < 70 && x > 23
34+
then
35+
89 + x
36+
else
37+
if x > 20 then g x + 20 else if x > -2 then 103 else 99
38+
[@@decomp top ()]`))
39+
})

imlformat/test/demo.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ let
33
x = (x +
44
1)
55

6+
let z = - 1
7+
let q = - 1.0
8+
9+
let l = 1 :: []
10+
611
let
712
g y =
813
(y *.
@@ -21,6 +26,8 @@ instance (fun x
2126
> 0)
2227
)
2328

29+
let f x = if x = 2 then 3 else if x = 4 then 5 else 6
30+
2431
eval
2532
(f 0);;
2633

@@ -63,6 +70,10 @@ g
6370
=
6471
42
6572

73+
let f x =
74+
let y = x + 1 in
75+
y - 1
76+
6677

6778
(* Comment A. *)
6879

imlformat/test/operators.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { expect, test } from '@jest/globals';
2+
3+
import { format } from "../imlformat.format";
4+
5+
test("Example from OCaml", () => {
6+
format(`3 + 3 mod 2, 3 + (3 mod 2), (3 + 3) mod 2`).then(x =>
7+
expect(x).toEqual(`(3 + 3 mod 2, 3 + 3 mod 2, (3 + 3) mod 2)`))
8+
})

imlformat/test/theorems.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ theorem
1313
&& f
1414
y > y
1515
&& f z > z
16-
[@@timeout 3600]
17-
[@@disable f] [@@by [%expand "f"] @> auto]
16+
[@@timeout
17+
3600 ]
18+
[@@disable f ] [@@by
19+
[%expand "f"]
20+
@>
21+
auto]
1822
[@@by
1923
some
2024
other
@@ -25,7 +29,7 @@ theorem
2529
let f x = x + 1
2630
2731
theorem thm1 x (y : int) z =
28-
((f x) > x) && (((f y) > y) && ((f z) > z))
32+
f x > x && f y > y && f z > z
2933
[@@timeout 3600]
3034
[@@disable f]
3135
[@@by [%expand "f"] @> auto]

0 commit comments

Comments
 (0)