From 98590b2e4a2087d5ee86a091424db16a53315f98 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Thu, 21 Mar 2019 23:01:21 +0100 Subject: [PATCH] Added support for removal from sets. Syntax: remove e from set s --- AST.ml | 19 +++++++++++++++++++ AST.mli | 9 +++++++++ Parser.mly | 13 +++++++++++++ 3 files changed, 41 insertions(+) diff --git a/AST.ml b/AST.ml index e7240a98d..426c24366 100644 --- a/AST.ml +++ b/AST.ml @@ -334,6 +334,15 @@ and single_instr = | RecordPatch of record_patch reg | MapPatch of map_patch reg | MapRemove of map_remove reg +| SetRemove of set_remove reg + +and set_remove = { + kwd_remove : kwd_remove; + element : expr; + kwd_from : kwd_from; + kwd_set : kwd_set; + set : path +} and map_remove = { kwd_remove : kwd_remove; @@ -713,6 +722,7 @@ let instr_to_region = function | Single RecordPatch {region; _} | Single MapPatch {region; _} | Single MapRemove {region; _} +| Single SetRemove {region; _} | Block {region; _} -> region let pattern_to_region = function @@ -1010,6 +1020,7 @@ and print_single_instr = function | RecordPatch {value; _} -> print_record_patch value | MapPatch {value; _} -> print_map_patch value | MapRemove {value; _} -> print_map_remove value +| SetRemove {value; _} -> print_set_remove value and print_fail {kwd_fail; fail_expr} = print_token kwd_fail "fail"; @@ -1259,6 +1270,14 @@ and print_map_remove node = print_token kwd_map "map"; print_path map +and print_set_remove node = + let {kwd_remove; element; kwd_from; kwd_set; set} = node in + print_token kwd_remove "remove"; + print_expr element; + print_token kwd_from "from"; + print_token kwd_set "set"; + print_path set + and print_map_injection {value; _} = let {opening; bindings; terminator; close} = value in print_token opening "map"; diff --git a/AST.mli b/AST.mli index c1d50aa49..d411b1ed7 100644 --- a/AST.mli +++ b/AST.mli @@ -318,6 +318,15 @@ and single_instr = | RecordPatch of record_patch reg | MapPatch of map_patch reg | MapRemove of map_remove reg +| SetRemove of set_remove reg + +and set_remove = { + kwd_remove : kwd_remove; + element : expr; + kwd_from : kwd_from; + kwd_set : kwd_set; + set : path +} and map_remove = { kwd_remove : kwd_remove; diff --git a/Parser.mly b/Parser.mly index dab4effda..448eb9ad5 100644 --- a/Parser.mly +++ b/Parser.mly @@ -475,6 +475,19 @@ single_instr: | record_patch { RecordPatch $1 } | map_patch { MapPatch $1 } | map_remove { MapRemove $1 } +| set_remove { SetRemove $1 } + +set_remove: + Remove expr From Set path { + let region = cover $1 (path_to_region $5) in + let value = { + kwd_remove = $1; + element = $2; + kwd_from = $3; + kwd_set = $4; + set = $5} + in {region; value} + } map_remove: Remove expr From Map path {