Added construct remove k from map m.

This commit is contained in:
Christian Rinderknecht 2019-03-21 21:55:59 +01:00
parent 285be32729
commit 1e65c63d99
No known key found for this signature in database
GPG Key ID: 9446816CFD267040
7 changed files with 60 additions and 1 deletions

21
AST.ml
View File

@ -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";

11
AST.mli
View File

@ -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;

View File

@ -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" *)

View File

@ -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 _

View File

@ -48,6 +48,7 @@
%token <Region.t> Const (* "const" *)
%token <Region.t> Down (* "down" *)
%token <Region.t> Fail (* "fail" *)
%token <Region.t> From (* "from" *)
%token <Region.t> If (* "if" *)
%token <Region.t> In (* "in" *)
%token <Region.t> Is (* "is" *)
@ -65,6 +66,7 @@
%token <Region.t> Patch (* "patch" *)
%token <Region.t> Procedure (* "procedure" *)
%token <Region.t> Record (* "record" *)
%token <Region.t> Remove (* "remove" *)
%token <Region.t> Skip (* "skip" *)
%token <Region.t> Step (* "step" *)
%token <Region.t> Storage (* "storage" *)

View File

@ -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 {

View File

@ -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)