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;
|
||||
test : test_expr;
|
||||
kwd_then : kwd_then;
|
||||
ifso : instruction;
|
||||
ifso : ifso;
|
||||
terminator : semi option;
|
||||
kwd_else : kwd_else;
|
||||
ifnot : instruction
|
||||
}
|
||||
|
||||
and ifso =
|
||||
ThenInstr of instruction
|
||||
| ThenBlock of (instructions * semi option) braces reg
|
||||
|
||||
and test_expr =
|
||||
GenExpr of expr
|
||||
| SetMem of set_membership reg
|
||||
@ -1072,11 +1076,21 @@ and print_conditional node =
|
||||
print_token kwd_if "if";
|
||||
print_test_expr test;
|
||||
print_token kwd_then "then";
|
||||
print_instruction ifso;
|
||||
print_ifso ifso;
|
||||
print_terminator terminator;
|
||||
print_token kwd_else "else";
|
||||
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
|
||||
GenExpr e -> print_expr e
|
||||
| SetMem m -> print_set_membership m
|
||||
|
6
AST.mli
6
AST.mli
@ -390,12 +390,16 @@ and conditional = {
|
||||
kwd_if : kwd_if;
|
||||
test : test_expr;
|
||||
kwd_then : kwd_then;
|
||||
ifso : instruction;
|
||||
ifso : ifso;
|
||||
terminator : semi option;
|
||||
kwd_else : kwd_else;
|
||||
ifnot : instruction
|
||||
}
|
||||
|
||||
and ifso =
|
||||
ThenInstr of instruction
|
||||
| ThenBlock of (instructions * semi option) braces reg
|
||||
|
||||
and test_expr =
|
||||
GenExpr of expr
|
||||
| SetMem of set_membership reg
|
||||
|
16
Parser.mly
16
Parser.mly
@ -580,7 +580,7 @@ proc_call:
|
||||
fun_call { $1 }
|
||||
|
||||
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 value = {
|
||||
kwd_if = $1;
|
||||
@ -593,6 +593,20 @@ conditional:
|
||||
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:
|
||||
expr { GenExpr $1 }
|
||||
| set_membership { SetMem $1 }
|
||||
|
@ -28,12 +28,11 @@ entrypoint withdraw (storage store : store; const sender : address)
|
||||
begin
|
||||
if sender = owner then
|
||||
if now (Unit) >= store.deadline then
|
||||
if balance >= store.goal then
|
||||
begin
|
||||
if balance >= store.goal then {
|
||||
store.funded := True;
|
||||
// patch store with record funded = True end;
|
||||
operations := [Transfer (owner, balance)]
|
||||
end
|
||||
operations := [Transfer (owner, balance)];
|
||||
};
|
||||
else fail "Below target"
|
||||
else fail "Too soon"
|
||||
else skip
|
||||
|
Loading…
Reference in New Issue
Block a user