diff --git a/AST.ml b/AST.ml index 5dd703a37..a40e21308 100644 --- a/AST.ml +++ b/AST.ml @@ -390,13 +390,17 @@ and case = { and assignment = { lhs : lhs; assign : assign; - expr : expr + rhs : rhs } and lhs = Path of path | MapPath of map_lookup reg +and rhs = + Expr of expr +| NoneExpr of c_None + and loop = While of while_loop reg | For of for_loop @@ -727,6 +731,10 @@ let lhs_to_region = function Path path -> path_to_region path | MapPath {region; _} -> region +let rhs_to_region = function + Expr e -> expr_to_region e +| NoneExpr r -> r + (* Printing the tokens with their source regions *) let printf = Printf.printf @@ -1028,10 +1036,14 @@ and print_case {value; _} = print_instruction instr and print_assignment {value; _} = - let {lhs; assign; expr} = value in + let {lhs; assign; rhs} = value in print_lhs lhs; print_token assign ":="; - print_expr expr + print_rhs rhs + +and print_rhs = function + Expr e -> print_expr e +| NoneExpr r -> print_token r "None" and print_lhs = function Path path -> print_path path diff --git a/AST.mli b/AST.mli index d7bbcfdd8..31e317ff5 100644 --- a/AST.mli +++ b/AST.mli @@ -374,13 +374,17 @@ and case = { and assignment = { lhs : lhs; assign : assign; - expr : expr + rhs : rhs; } and lhs = Path of path | MapPath of map_lookup reg +and rhs = + Expr of expr +| NoneExpr of c_None + and loop = While of while_loop reg | For of for_loop @@ -593,6 +597,7 @@ val pattern_to_region : pattern -> Region.t 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 (* Printing *) diff --git a/Parser.mly b/Parser.mly index 2c05c414f..0a08a89a6 100644 --- a/Parser.mly +++ b/Parser.mly @@ -543,12 +543,17 @@ case: } assignment: - lhs ASS expr { - let region = cover (lhs_to_region $1) (expr_to_region $3) - and value = {lhs = $1; assign = $2; expr = $3} + lhs ASS rhs { + let stop = rhs_to_region $3 in + let region = cover (lhs_to_region $1) stop + and value = {lhs = $1; assign = $2; rhs = $3} in {region; value} } +rhs: + expr { Expr $1 } +| C_None { NoneExpr $1 : rhs } + lhs: path { Path $1 } | map_lookup { MapPath $1 } @@ -580,7 +585,6 @@ for_loop: block = $7} in For (ForInt {region; value}) } - | For var option(arrow_clause) In expr block { let region = cover $1 $6.region in let value = { diff --git a/Tests/crowdfunding.ligo b/Tests/crowdfunding.ligo index 243b8fcd0..e60a2a86e 100644 --- a/Tests/crowdfunding.ligo +++ b/Tests/crowdfunding.ligo @@ -58,7 +58,7 @@ entrypoint claim (storage store : store; const sender : address) else begin operations := [Transfer (sender, amount)]; - store.backers[sender] := (None : option (nat)) + store.backers[sender] := None end end end with (store, operations)