diff --git a/AST.ml b/AST.ml index 0a7e0c3fc..a332cb37f 100644 --- a/AST.ml +++ b/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 diff --git a/AST.mli b/AST.mli index 45086b17b..c324577a6 100644 --- a/AST.mli +++ b/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 diff --git a/Parser.mly b/Parser.mly index 2bbffd9d3..79a3db6ad 100644 --- a/Parser.mly +++ b/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 } diff --git a/Tests/crowdfunding.ligo b/Tests/crowdfunding.ligo index 1d00168a0..343bf9b9b 100644 --- a/Tests/crowdfunding.ligo +++ b/Tests/crowdfunding.ligo @@ -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