From 1e65c63d99d5d106c6097bdd7e54a686f76955e0 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Thu, 21 Mar 2019 21:55:59 +0100 Subject: [PATCH] Added construct `remove k from map m`. --- AST.ml | 21 +++++++++++++++++++++ AST.mli | 11 +++++++++++ LexToken.mli | 2 ++ LexToken.mll | 10 ++++++++++ ParToken.mly | 2 ++ Parser.mly | 13 +++++++++++++ Tests/crowdfunding.ligo | 2 +- 7 files changed, 60 insertions(+), 1 deletion(-) diff --git a/AST.ml b/AST.ml index 111550bf5..3cf7d59a4 100644 --- a/AST.ml +++ b/AST.ml @@ -49,6 +49,7 @@ type kwd_end = Region.t type kwd_entrypoint = Region.t type kwd_fail = Region.t type kwd_for = Region.t +type kwd_from = Region.t type kwd_function = Region.t type kwd_if = Region.t type kwd_in = Region.t @@ -61,6 +62,7 @@ type kwd_or = Region.t type kwd_patch = Region.t type kwd_procedure = Region.t type kwd_record = Region.t +type kwd_remove = Region.t type kwd_skip = Region.t type kwd_step = Region.t type kwd_storage = Region.t @@ -329,6 +331,15 @@ and single_instr = | Skip of kwd_skip | RecordPatch of record_patch reg | MapPatch of map_patch reg +| MapRemove of map_remove reg + +and map_remove = { + kwd_remove : kwd_remove; + key : expr; + kwd_from : kwd_from; + kwd_map : kwd_map; + map : path +} and map_patch = { kwd_patch : kwd_patch; @@ -703,6 +714,7 @@ let instr_to_region = function | Single Fail {region; _} | Single RecordPatch {region; _} | Single MapPatch {region; _} +| Single MapRemove {region; _} | Block {region; _} -> region let pattern_to_region = function @@ -999,6 +1011,7 @@ and print_single_instr = function | Skip kwd_skip -> print_token kwd_skip "skip" | RecordPatch {value; _} -> print_record_patch value | MapPatch {value; _} -> print_map_patch value +| MapRemove {value; _} -> print_map_remove value and print_fail {kwd_fail; fail_expr} = print_token kwd_fail "fail"; @@ -1242,6 +1255,14 @@ and print_map_patch node = print_token kwd_with "with"; print_map_injection map_inj +and print_map_remove node = + let {kwd_remove; key; kwd_from; kwd_map; map} = node in + print_token kwd_remove "remove"; + print_expr key; + print_token kwd_from "from"; + print_token kwd_map "map"; + print_path map + and print_map_injection {value; _} = let {opening; bindings; terminator; close} = value in print_token opening "record"; diff --git a/AST.mli b/AST.mli index 0ca9d2fa4..7cf95ce96 100644 --- a/AST.mli +++ b/AST.mli @@ -33,6 +33,7 @@ type kwd_end = Region.t type kwd_entrypoint = Region.t type kwd_fail = Region.t type kwd_for = Region.t +type kwd_from = Region.t type kwd_function = Region.t type kwd_if = Region.t type kwd_in = Region.t @@ -45,6 +46,7 @@ type kwd_or = Region.t type kwd_patch = Region.t type kwd_procedure = Region.t type kwd_record = Region.t +type kwd_remove = Region.t type kwd_skip = Region.t type kwd_step = Region.t type kwd_storage = Region.t @@ -313,6 +315,15 @@ and single_instr = | Skip of kwd_skip | RecordPatch of record_patch reg | MapPatch of map_patch reg +| MapRemove of map_remove reg + +and map_remove = { + kwd_remove : kwd_remove; + key : expr; + kwd_from : kwd_from; + kwd_map : kwd_map; + map : path +} and map_patch = { kwd_patch : kwd_patch; diff --git a/LexToken.mli b/LexToken.mli index b1503bd99..364e2c91c 100644 --- a/LexToken.mli +++ b/LexToken.mli @@ -75,6 +75,7 @@ type t = | Entrypoint of Region.t (* "entrypoint" *) | Fail of Region.t (* "fail" *) | For of Region.t (* "for" *) +| From of Region.t (* "from" *) | Function of Region.t (* "function" *) | If of Region.t (* "if" *) | In of Region.t (* "in" *) @@ -87,6 +88,7 @@ type t = | Patch of Region.t (* "patch" *) | Procedure of Region.t (* "procedure" *) | Record of Region.t (* "record" *) +| Remove of Region.t (* "remove" *) | Skip of Region.t (* "skip" *) | Step of Region.t (* "step" *) | Storage of Region.t (* "storage" *) diff --git a/LexToken.mll b/LexToken.mll index d7530b948..11b6b9e7f 100644 --- a/LexToken.mll +++ b/LexToken.mll @@ -74,6 +74,7 @@ type t = | Entrypoint of Region.t (* "entrypoint" *) | Fail of Region.t (* "fail" *) | For of Region.t (* "for" *) +| From of Region.t (* "from" *) | Function of Region.t (* "function" *) | If of Region.t (* "if" *) | In of Region.t (* "in" *) @@ -86,6 +87,7 @@ type t = | Patch of Region.t (* "patch" *) | Procedure of Region.t (* "procedure" *) | Record of Region.t (* "record" *) +| Remove of Region.t (* "remove" *) | Skip of Region.t (* "skip" *) | Step of Region.t (* "step" *) | Storage of Region.t (* "storage" *) @@ -194,6 +196,7 @@ let proj_token = function | Entrypoint region -> region, "Entrypoint" | Fail region -> region, "Fail" | For region -> region, "For" +| From region -> region, "From" | Function region -> region, "Function" | If region -> region, "If" | In region -> region, "In" @@ -206,6 +209,7 @@ let proj_token = function | Patch region -> region, "Patch" | Procedure region -> region, "Procedure" | Record region -> region, "Record" +| Remove region -> region, "Remove" | Skip region -> region, "Skip" | Step region -> region, "Step" | Storage region -> region, "Storage" @@ -280,6 +284,7 @@ let to_lexeme = function | Is _ -> "is" | Entrypoint _ -> "entrypoint" | For _ -> "for" +| From _ -> "from" | Function _ -> "function" | Type _ -> "type" | Of _ -> "of" @@ -292,6 +297,7 @@ let to_lexeme = function | Patch _ -> "patch" | Procedure _ -> "procedure" | Record _ -> "record" +| Remove _ -> "remove" | Skip _ -> "skip" | Step _ -> "step" | Storage _ -> "storage" @@ -335,6 +341,7 @@ let keywords = [ (fun reg -> Is reg); (fun reg -> Entrypoint reg); (fun reg -> For reg); + (fun reg -> From reg); (fun reg -> Function reg); (fun reg -> Type reg); (fun reg -> Of reg); @@ -347,6 +354,7 @@ let keywords = [ (fun reg -> Patch reg); (fun reg -> Procedure reg); (fun reg -> Record reg); + (fun reg -> Remove reg); (fun reg -> Skip reg); (fun reg -> Step reg); (fun reg -> Storage reg); @@ -558,6 +566,7 @@ let is_kwd = function | Is _ | Entrypoint _ | For _ +| From _ | Function _ | Type _ | Of _ @@ -570,6 +579,7 @@ let is_kwd = function | Patch _ | Procedure _ | Record _ +| Remove _ | Skip _ | Step _ | Storage _ diff --git a/ParToken.mly b/ParToken.mly index 2ffbd93ad..59eceea95 100644 --- a/ParToken.mly +++ b/ParToken.mly @@ -48,6 +48,7 @@ %token Const (* "const" *) %token Down (* "down" *) %token Fail (* "fail" *) +%token From (* "from" *) %token If (* "if" *) %token In (* "in" *) %token Is (* "is" *) @@ -65,6 +66,7 @@ %token Patch (* "patch" *) %token Procedure (* "procedure" *) %token Record (* "record" *) +%token Remove (* "remove" *) %token Skip (* "skip" *) %token Step (* "step" *) %token Storage (* "storage" *) diff --git a/Parser.mly b/Parser.mly index b8a582c0d..9fca805fb 100644 --- a/Parser.mly +++ b/Parser.mly @@ -464,6 +464,19 @@ single_instr: | Skip { Skip $1 } | record_patch { RecordPatch $1 } | map_patch { MapPatch $1 } +| map_remove { MapRemove $1 } + +map_remove: + Remove expr From Map path { + let region = cover $1 (path_to_region $5) in + let value = { + kwd_remove = $1; + key = $2; + kwd_from = $3; + kwd_map = $4; + map = $5} + in {region; value} + } map_patch: Patch path With map_injection { diff --git a/Tests/crowdfunding.ligo b/Tests/crowdfunding.ligo index 5002e0549..4e3c2edba 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 + remove sender from map store.backers end end end with (store, operations)