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

4
AST.ml
View File

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

View File

@ -381,6 +381,7 @@ and conditional = {
test : expr; test : expr;
kwd_then : kwd_then; kwd_then : kwd_then;
ifso : instruction; ifso : instruction;
terminator : semi option;
kwd_else : kwd_else; kwd_else : kwd_else;
ifnot : instruction ifnot : instruction
} }

View File

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

View File

@ -6,9 +6,6 @@ type store is
funded : bool; funded : bool;
end 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; entrypoint contribute (storage store : store;
const sender : address; const sender : address;
const amount : mutez) const amount : mutez)
@ -16,7 +13,7 @@ entrypoint contribute (storage store : store;
var operations : list (operation) := [] var operations : list (operation) := []
begin begin
if now > store.deadline then if now > store.deadline then
fail "Deadline passed" fail "Deadline passed";
else else
case store.backers[sender] of case store.backers[sender] of
None -> store.backers[sender] := Some (amount) None -> store.backers[sender] := Some (amount)
@ -59,7 +56,7 @@ entrypoint claim (storage store : store; const sender : address)
else else
begin begin
operations := [Transfer (sender, amount)]; operations := [Transfer (sender, amount)];
remove sender from map store.backers remove sender from map store.backers;
end end
end end
end with (store, operations) end with (store, operations)