Added alternate syntax for conditionals in "then" clauses.
New syntax: if ... then { ... } else ...
This commit is contained in:
parent
457a0085f7
commit
aced77e085
18
AST.ml
18
AST.ml
@ -406,12 +406,16 @@ and conditional = {
|
|||||||
kwd_if : kwd_if;
|
kwd_if : kwd_if;
|
||||||
test : test_expr;
|
test : test_expr;
|
||||||
kwd_then : kwd_then;
|
kwd_then : kwd_then;
|
||||||
ifso : instruction;
|
ifso : ifso;
|
||||||
terminator : semi option;
|
terminator : semi option;
|
||||||
kwd_else : kwd_else;
|
kwd_else : kwd_else;
|
||||||
ifnot : instruction
|
ifnot : instruction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
and ifso =
|
||||||
|
ThenInstr of instruction
|
||||||
|
| ThenBlock of (instructions * semi option) braces reg
|
||||||
|
|
||||||
and test_expr =
|
and test_expr =
|
||||||
GenExpr of expr
|
GenExpr of expr
|
||||||
| SetMem of set_membership reg
|
| SetMem of set_membership reg
|
||||||
@ -1072,11 +1076,21 @@ and print_conditional node =
|
|||||||
print_token kwd_if "if";
|
print_token kwd_if "if";
|
||||||
print_test_expr test;
|
print_test_expr test;
|
||||||
print_token kwd_then "then";
|
print_token kwd_then "then";
|
||||||
print_instruction ifso;
|
print_ifso ifso;
|
||||||
print_terminator terminator;
|
print_terminator terminator;
|
||||||
print_token kwd_else "else";
|
print_token kwd_else "else";
|
||||||
print_instruction ifnot
|
print_instruction ifnot
|
||||||
|
|
||||||
|
and print_ifso = function
|
||||||
|
ThenInstr instr -> print_instruction instr
|
||||||
|
| ThenBlock {value; _} ->
|
||||||
|
let {lbrace; inside; rbrace} = value in
|
||||||
|
let instr, terminator = inside in
|
||||||
|
print_token lbrace "{";
|
||||||
|
print_instructions instr;
|
||||||
|
print_terminator terminator;
|
||||||
|
print_token rbrace "}"
|
||||||
|
|
||||||
and print_test_expr = function
|
and print_test_expr = function
|
||||||
GenExpr e -> print_expr e
|
GenExpr e -> print_expr e
|
||||||
| SetMem m -> print_set_membership m
|
| SetMem m -> print_set_membership m
|
||||||
|
6
AST.mli
6
AST.mli
@ -390,12 +390,16 @@ and conditional = {
|
|||||||
kwd_if : kwd_if;
|
kwd_if : kwd_if;
|
||||||
test : test_expr;
|
test : test_expr;
|
||||||
kwd_then : kwd_then;
|
kwd_then : kwd_then;
|
||||||
ifso : instruction;
|
ifso : ifso;
|
||||||
terminator : semi option;
|
terminator : semi option;
|
||||||
kwd_else : kwd_else;
|
kwd_else : kwd_else;
|
||||||
ifnot : instruction
|
ifnot : instruction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
and ifso =
|
||||||
|
ThenInstr of instruction
|
||||||
|
| ThenBlock of (instructions * semi option) braces reg
|
||||||
|
|
||||||
and test_expr =
|
and test_expr =
|
||||||
GenExpr of expr
|
GenExpr of expr
|
||||||
| SetMem of set_membership reg
|
| SetMem of set_membership reg
|
||||||
|
16
Parser.mly
16
Parser.mly
@ -580,7 +580,7 @@ proc_call:
|
|||||||
fun_call { $1 }
|
fun_call { $1 }
|
||||||
|
|
||||||
conditional:
|
conditional:
|
||||||
If test_expr Then instruction option(SEMI) Else instruction {
|
If test_expr Then ifso option(SEMI) Else instruction {
|
||||||
let region = cover $1 (instr_to_region $7) in
|
let region = cover $1 (instr_to_region $7) in
|
||||||
let value = {
|
let value = {
|
||||||
kwd_if = $1;
|
kwd_if = $1;
|
||||||
@ -593,6 +593,20 @@ conditional:
|
|||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ifso:
|
||||||
|
instruction {
|
||||||
|
ThenInstr $1
|
||||||
|
}
|
||||||
|
| LBRACE series(instruction,RBRACE) {
|
||||||
|
let first, (others, terminator, closing) = $2 in
|
||||||
|
let region = cover $1 closing in
|
||||||
|
let value = {
|
||||||
|
lbrace = $1;
|
||||||
|
inside = (first, others), terminator;
|
||||||
|
rbrace = closing} in
|
||||||
|
ThenBlock {value; region}
|
||||||
|
}
|
||||||
|
|
||||||
test_expr:
|
test_expr:
|
||||||
expr { GenExpr $1 }
|
expr { GenExpr $1 }
|
||||||
| set_membership { SetMem $1 }
|
| set_membership { SetMem $1 }
|
||||||
|
@ -28,12 +28,11 @@ entrypoint withdraw (storage store : store; const sender : address)
|
|||||||
begin
|
begin
|
||||||
if sender = owner then
|
if sender = owner then
|
||||||
if now (Unit) >= store.deadline then
|
if now (Unit) >= store.deadline then
|
||||||
if balance >= store.goal then
|
if balance >= store.goal then {
|
||||||
begin
|
|
||||||
store.funded := True;
|
store.funded := True;
|
||||||
// patch store with record funded = True end;
|
// patch store with record funded = True end;
|
||||||
operations := [Transfer (owner, balance)]
|
operations := [Transfer (owner, balance)];
|
||||||
end
|
};
|
||||||
else fail "Below target"
|
else fail "Below target"
|
||||||
else fail "Too soon"
|
else fail "Too soon"
|
||||||
else skip
|
else skip
|
||||||
|
Loading…
Reference in New Issue
Block a user