I added an optional semi-colon before "else".

Syntax: if ... then ...; else ...
This commit is contained in:
Christian Rinderknecht 2019-03-21 23:18:09 +01:00
parent c76ec00c9b
commit 19f6981ae7
No known key found for this signature in database
GPG Key ID: 9446816CFD267040
4 changed files with 27 additions and 26 deletions

16
AST.ml
View File

@ -393,12 +393,13 @@ and fail_instr = {
}
and conditional = {
kwd_if : kwd_if;
test : expr;
kwd_then : kwd_then;
ifso : instruction;
kwd_else : kwd_else;
ifnot : instruction
kwd_if : kwd_if;
test : expr;
kwd_then : kwd_then;
ifso : instruction;
terminator : semi option;
kwd_else : kwd_else;
ifnot : instruction
}
and case_instr = {
@ -1037,12 +1038,13 @@ and print_fail {kwd_fail; fail_expr} =
print_expr fail_expr
and print_conditional node =
let {kwd_if; test; kwd_then; ifso;
let {kwd_if; test; kwd_then; ifso; terminator;
kwd_else; ifnot} = node in
print_token kwd_if "if";
print_expr test;
print_token kwd_then "then";
print_instruction ifso;
print_terminator terminator;
print_token kwd_else "else";
print_instruction ifnot

13
AST.mli
View File

@ -377,12 +377,13 @@ and fail_instr = {
}
and conditional = {
kwd_if : kwd_if;
test : expr;
kwd_then : kwd_then;
ifso : instruction;
kwd_else : kwd_else;
ifnot : instruction
kwd_if : kwd_if;
test : expr;
kwd_then : kwd_then;
ifso : instruction;
terminator : semi option;
kwd_else : kwd_else;
ifnot : instruction
}
and case_instr = {

View File

@ -581,15 +581,16 @@ proc_call:
fun_call { $1 }
conditional:
If expr Then instruction Else instruction {
let region = cover $1 (instr_to_region $6) in
If expr Then instruction option(SEMI) Else instruction {
let region = cover $1 (instr_to_region $7) in
let value = {
kwd_if = $1;
test = $2;
kwd_then = $3;
ifso = $4;
kwd_else = $5;
ifnot = $6}
kwd_if = $1;
test = $2;
kwd_then = $3;
ifso = $4;
terminator = $5;
kwd_else = $6;
ifnot = $7}
in {region; value}
}

View File

@ -6,9 +6,6 @@ type store is
funded : bool;
end
const foo : map (string, nat) = map "X" -> 10; "Y" -> 11 end
const bar : set (int) = set 1; 1+1; f(3); end
entrypoint contribute (storage store : store;
const sender : address;
const amount : mutez)
@ -16,7 +13,7 @@ entrypoint contribute (storage store : store;
var operations : list (operation) := []
begin
if now > store.deadline then
fail "Deadline passed"
fail "Deadline passed";
else
case store.backers[sender] of
None -> store.backers[sender] := Some (amount)
@ -59,7 +56,7 @@ entrypoint claim (storage store : store; const sender : address)
else
begin
operations := [Transfer (sender, amount)];
remove sender from map store.backers
remove sender from map store.backers;
end
end
end with (store, operations)