diff --git a/AST.ml b/AST.ml index a332cb37f..134552265 100644 --- a/AST.ml +++ b/AST.ml @@ -406,15 +406,15 @@ and conditional = { kwd_if : kwd_if; test : test_expr; kwd_then : kwd_then; - ifso : ifso; + ifso : if_clause; terminator : semi option; kwd_else : kwd_else; - ifnot : instruction + ifnot : if_clause } -and ifso = - ThenInstr of instruction -| ThenBlock of (instructions * semi option) braces reg +and if_clause = + ClauseInstr of instruction +| ClauseBlock of (instructions * semi option) braces reg and test_expr = GenExpr of expr @@ -759,6 +759,10 @@ let instr_to_region = function | Single SetRemove {region; _} | Block {region; _} -> region +let if_clause_to_region = function + ClauseInstr instr -> instr_to_region instr +| ClauseBlock {region; _} -> region + let pattern_to_region = function PCons {region; _} | PVar {region; _} @@ -1073,17 +1077,17 @@ and print_fail {kwd_fail; fail_expr} = and print_conditional node = let {kwd_if; test; kwd_then; ifso; terminator; kwd_else; ifnot} = node in - print_token kwd_if "if"; - print_test_expr test; - print_token kwd_then "then"; - print_ifso ifso; - print_terminator terminator; - print_token kwd_else "else"; - print_instruction ifnot + print_token kwd_if "if"; + print_test_expr test; + print_token kwd_then "then"; + print_if_clause ifso; + print_terminator terminator; + print_token kwd_else "else"; + print_if_clause ifnot -and print_ifso = function - ThenInstr instr -> print_instruction instr -| ThenBlock {value; _} -> +and print_if_clause = function + ClauseInstr instr -> print_instruction instr +| ClauseBlock {value; _} -> let {lbrace; inside; rbrace} = value in let instr, terminator = inside in print_token lbrace "{"; diff --git a/AST.mli b/AST.mli index c324577a6..c026c0630 100644 --- a/AST.mli +++ b/AST.mli @@ -390,15 +390,15 @@ and conditional = { kwd_if : kwd_if; test : test_expr; kwd_then : kwd_then; - ifso : ifso; + ifso : if_clause; terminator : semi option; kwd_else : kwd_else; - ifnot : instruction + ifnot : if_clause } -and ifso = - ThenInstr of instruction -| ThenBlock of (instructions * semi option) braces reg +and if_clause = + ClauseInstr of instruction +| ClauseBlock of (instructions * semi option) braces reg and test_expr = GenExpr of expr @@ -651,6 +651,7 @@ val local_decl_to_region : local_decl -> Region.t val path_to_region : path -> Region.t val lhs_to_region : lhs -> Region.t val rhs_to_region : rhs -> Region.t +val if_clause_to_region : if_clause -> Region.t (* Printing *) diff --git a/Parser.mly b/Parser.mly index 79a3db6ad..2365810b5 100644 --- a/Parser.mly +++ b/Parser.mly @@ -580,8 +580,8 @@ proc_call: fun_call { $1 } conditional: - If test_expr Then ifso option(SEMI) Else instruction { - let region = cover $1 (instr_to_region $7) in + If test_expr Then if_clause option(SEMI) Else if_clause { + let region = cover $1 (if_clause_to_region $7) in let value = { kwd_if = $1; test = $2; @@ -593,9 +593,9 @@ conditional: in {region; value} } -ifso: +if_clause: instruction { - ThenInstr $1 + ClauseInstr $1 } | LBRACE series(instruction,RBRACE) { let first, (others, terminator, closing) = $2 in @@ -604,7 +604,7 @@ ifso: lbrace = $1; inside = (first, others), terminator; rbrace = closing} in - ThenBlock {value; region} + ClauseBlock {value; region} } test_expr: diff --git a/Tests/crowdfunding.ligo b/Tests/crowdfunding.ligo index 343bf9b9b..ec6119096 100644 --- a/Tests/crowdfunding.ligo +++ b/Tests/crowdfunding.ligo @@ -34,7 +34,7 @@ entrypoint withdraw (storage store : store; const sender : address) operations := [Transfer (owner, balance)]; }; else fail "Below target" - else fail "Too soon" + else { fail "Too soon"; } else skip end with (store, operations)