I added an optional semi-colon before "else".
Syntax: if ... then ...; else ...
This commit is contained in:
parent
c76ec00c9b
commit
19f6981ae7
16
AST.ml
16
AST.ml
@ -393,12 +393,13 @@ and fail_instr = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
and conditional = {
|
and conditional = {
|
||||||
kwd_if : kwd_if;
|
kwd_if : kwd_if;
|
||||||
test : expr;
|
test : expr;
|
||||||
kwd_then : kwd_then;
|
kwd_then : kwd_then;
|
||||||
ifso : instruction;
|
ifso : instruction;
|
||||||
kwd_else : kwd_else;
|
terminator : semi option;
|
||||||
ifnot : instruction
|
kwd_else : kwd_else;
|
||||||
|
ifnot : instruction
|
||||||
}
|
}
|
||||||
|
|
||||||
and case_instr = {
|
and case_instr = {
|
||||||
@ -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
|
||||||
|
|
||||||
|
13
AST.mli
13
AST.mli
@ -377,12 +377,13 @@ and fail_instr = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
and conditional = {
|
and conditional = {
|
||||||
kwd_if : kwd_if;
|
kwd_if : kwd_if;
|
||||||
test : expr;
|
test : expr;
|
||||||
kwd_then : kwd_then;
|
kwd_then : kwd_then;
|
||||||
ifso : instruction;
|
ifso : instruction;
|
||||||
kwd_else : kwd_else;
|
terminator : semi option;
|
||||||
ifnot : instruction
|
kwd_else : kwd_else;
|
||||||
|
ifnot : instruction
|
||||||
}
|
}
|
||||||
|
|
||||||
and case_instr = {
|
and case_instr = {
|
||||||
|
17
Parser.mly
17
Parser.mly
@ -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}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user