Skip to content

Commit 9c0f893

Browse files
committed
[Tolk] Optional semicolon for the last statement in a block
While semicolons are required between statements to disambiguate sequencing, the trailing semicolon on the last statement is now optional. This change is backward-compatible and does not affect existing code.
1 parent ac57626 commit 9c0f893

25 files changed

+201
-233
lines changed

tolk-tester/tests/a-tests.tolk

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ fun f(a: int, b: int, c: int, d: int, e: int, f: int): (int, int) {
44
__expect_type(D, "int");
55
__expect_type(D*D, "int");
66
__expect_type(calc_phi, "() -> int");
7-
return (Dx/D,Dy/D,);
7+
return (Dx/D,Dy/D,)
88
};;;;
99

1010
fun calc_phi(): int {
1111
var n = 1;
12-
repeat (70) { n*=10; };
12+
repeat (70) { n*=10 };
1313
var p= 1;
1414
var `q`=1;
1515
_=`q`;
1616
do {
17-
(p,q)=(q,p+q);
17+
(p,q)=(q,p+q)
1818
} while (q <= n); //;;
19-
return mulDivRound(p, n, q,);
19+
return mulDivRound(p, n, q,)
2020
}
2121

2222
fun calc_sqrt2(): int {
@@ -43,7 +43,7 @@ fun calc_root(m: int,) {
4343
k+=1;
4444
(a1, b1, c1) = (a, b, c);
4545
c+=b;
46-
c += b += a;
46+
c += b += a
4747
} while (c <= 0);
4848
(a, b, c) = (-c1, -b1, -a1);
4949
(p1, q1) = (k * p1+q1, p1);
@@ -67,12 +67,12 @@ fun ataninv(base: int, q: int): int { // computes base*atan(1/q)
6767

6868
fun calc_pi(): int {
6969
var base: int = 64;
70-
repeat (70) { base *= 10; }
70+
repeat (70) { base *= 10 }
7171
return (ataninv(base << 2, 5) - ataninv(base, 239))~>>4;
7272
}
7373

7474
fun main(): int {
75-
return calc_pi();
75+
return calc_pi()
7676
}
7777

7878
/**

tolk-tester/tests/if-else-tests.tolk

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,22 @@ fun doNothing(): void {}
6868

6969
@method_id(107)
7070
fun test7() {
71-
if (random()) { return doNothing(); }
71+
if (random()) { return doNothing() }
7272
// here we test that no "missing return" error
7373
}
7474

7575
fun withNoElse(op: int): int {
76-
if (op == 123) { return 100; }
77-
if (op == 234) { return 200; }
78-
if (op == 345) { return 300; }
79-
throw 0xFF;
76+
if (op == 123) { return 100 }
77+
if (op == 234) { return 200 }
78+
if (op == 345) { return 300 }
79+
throw 0xFF
8080
}
8181

8282
fun withElse(op: int): int {
83-
if (op == 123) { return 100; }
84-
else if (op == 234) { return 200; }
85-
else if (op == 345) { return 300; }
86-
return 0xFF;
83+
if (op == 123) { return 100 }
84+
else if (op == 234) { return 200 }
85+
else if (op == 345) { return 300 }
86+
return 0xFF
8787
}
8888

8989
fun withMatch(op: int): int {
@@ -92,7 +92,7 @@ fun withMatch(op: int): int {
9292
234 => return 200,
9393
345 => return 300,
9494
}
95-
throw 0xFF;
95+
throw 0xFF
9696
}
9797

9898
@method_id(108)

tolk-tester/tests/logical-operators.tolk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ fun compileTimeEval1(x: int) {
1313

1414
@method_id(101)
1515
fun withIfNot(x: int, y: int) {
16-
if (!x) { return 10; }
17-
else if (!y) { return 20; }
18-
return x+y;
16+
if (!x) { return 10 }
17+
else if (!y) { { return 20 } }
18+
return x+y
1919
}
2020

2121
@method_id(102)

tolk-tester/tests/match-by-expr-tests.tolk

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fun test1(x: int) {
88
C2 => 200,
99
2 + 1 => 300,
1010
else => 400
11-
};
11+
}
1212
}
1313

1414
@method_id(102)
@@ -19,7 +19,7 @@ fun test2() {
1919
C2 => 200,
2020
2 + 1 => 300,
2121
else => 400
22-
};
22+
}
2323
}
2424

2525
fun isGt10(x: int) { return x > 10; }
@@ -34,7 +34,7 @@ fun test3(init: int) {
3434

3535
@method_id(104)
3636
fun test4(x: int?) {
37-
return match(match(x) { null => 0, int => x * 2 }) { 0 => 0, 30 => 30, else => throw 123 };
37+
return match(match(x) { null => 0, int => x * 2 }) { 0 => 0, 30 => 30, else => throw 123 }
3838
}
3939

4040
@method_id(105)
@@ -44,9 +44,9 @@ fun test5(x: int) {
4444
10/C1 => 10,
4545
C2*10 => throw 500,
4646
else => 50
47-
};
47+
}
4848
} catch (excCode) {
49-
return excCode;
49+
return excCode
5050
}
5151
}
5252

@@ -60,8 +60,8 @@ fun test6(x: coins) {
6060
}
6161
var result2 = 0;
6262
match (x) {
63-
ton("0.05") => { result2 = 5; }
64-
ton("0.1") => { result2 = 10; }
63+
ton("0.05") => { result2 = 5 }
64+
ton("0.1") => { result2 = 10 }
6565
}
6666
return (result1, result2);
6767
}
@@ -94,7 +94,7 @@ fun test9(x: int | slice) {
9494
return match (x) {
9595
int => match (x) { 10 => 5, else => -1 },
9696
slice => match (x.loadInt(32)) { -1 => 0, 0 => 0, else => throw 20 }
97-
};
97+
}
9898
}
9999

100100
@method_id(110)
@@ -113,7 +113,7 @@ fun test11(x: bool) {
113113
return match (x) {
114114
true => false,
115115
else => !x,
116-
};
116+
}
117117
}
118118

119119

tolk-tester/tests/no-spaces.tolk

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const int10:int=10;
22

33
fun just10(): int { return int10; }
4-
fun eq(v: int): int { return`v`; }
4+
fun eq(v: int): int { return`v` }
55

6-
@method_id(101,) fun `get_-1` (): int {return-1;}
7-
@method_id(102,) fun `get_--1` (): int {return--1;}
8-
@method_id(103,) fun `get_---1`(): int {return---1;}
9-
@method_id(104,) fun `get_+++1`(): int {return+++1;}
10-
@method_id(105,) fun `get_+-+1`(): int {return+-+1;}
6+
@method_id(101,) fun `get_-1` (): int {return-1}
7+
@method_id(102,) fun `get_--1` (): int {return--1}
8+
@method_id(103,) fun `get_---1`(): int {return---1}
9+
@method_id(104,) fun `get_+++1`(): int {return+++1}
10+
@method_id(105,) fun `get_+-+1`(): int {return+-+1}
1111

1212
global `some()var`:int;
1313

@@ -26,7 +26,7 @@ global `some()var`:int;
2626
return[
2727
(just10()-3==just10()-(4)--1)|((2==2)&(eq(eq(10)) -3==just10()--13)),
2828
((flags&0xFF)!=0)
29-
];
29+
]
3030
}
3131

3232
@method_id(113)fun`unary+bitwise-constant`():[int,int,int]{
@@ -48,7 +48,7 @@ fun add3(a: int, b: int, c: int) { return a+b+c; }
4848
}
4949

5050
fun `load:u32`(mutate self: slice): int {
51-
return self.loadUint(32);
51+
return self.loadUint(32)
5252
}
5353

5454
@method_id(116) fun `call_~_via_backticks`():[int,int,int,int] {

tolk-tester/tests/nullable-types.tolk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ type MIntN = int?;
33
fun getNullable4(): MIntN { return 4; }
44
fun getNullableIntNull(): int? asm "PUSHNULL";
55

6-
fun eqInt(x: int) { return x; }
7-
fun eq<T>(x: T) { return x; }
6+
fun eqInt(x: int) { return x }
7+
fun eq<T>(x: T) { return x }
88

99
fun unwrap<T>(x: T?): T { return x!; }
1010
fun intOr0(x: int?): int { return null == x ? 0 : x!; }

tolk-tester/tests/smart-cast-tests.tolk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ fun test3(): int {
4747
return x;
4848
}
4949
if (random() > -1) {
50-
if (y == null) { return -1; }
51-
else { return y; }
50+
if (y == null) { return -1 }
51+
else { return y }
5252
}
5353
return 0;
5454
}
@@ -344,8 +344,8 @@ fun test33(): int {
344344

345345
fun test34() {
346346
var (x, y) = (getNullableInt(), getNullableInt());
347-
if (random()) { throw (x = 1, y = 2); }
348-
else { throw (x = 3, y = (1, getNullableInt()!).1); }
347+
if (random()) { throw (x = 1, y = 2) }
348+
else { throw (x = 3, y = (1, getNullableInt()!).1) }
349349
return x + y;
350350
}
351351

tolk-tester/tests/unbalanced-ret.tolk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ fun main(x: int): (int, int) {
44
x *= 2;
55
y += 1;
66
if (x == -10) {
7-
return (111, 0);
7+
return (111, 0)
88
}
99
}
10-
return (x + 1, y);
10+
return (x + 1, y)
1111
}
1212

1313
@inline
@@ -41,7 +41,7 @@ fun bar2(x: int, y: int): (int, int) {
4141
y = foo2(y);
4242
x *= 2;
4343
if (x == -10) {
44-
return (111, y);
44+
return (111, y)
4545
}
4646
}
4747
return (x + 1, y);

0 commit comments

Comments
 (0)