Refactoring of AST and parser (type [map_injection] removed).

This commit is contained in:
Christian Rinderknecht 2019-03-26 23:36:41 +01:00
parent b200239d82
commit e4eaad5385
No known key found for this signature in database
GPG Key ID: 9446816CFD267040
3 changed files with 32 additions and 51 deletions

52
AST.ml
View File

@ -370,21 +370,14 @@ and set_patch = {
kwd_patch : kwd_patch;
path : path;
kwd_with : kwd_with;
set_inj : injection reg
set_inj : expr injection reg
}
and map_patch = {
kwd_patch : kwd_patch;
path : path;
kwd_with : kwd_with;
map_inj : map_injection reg
}
and map_injection = {
opening : opening;
bindings : (binding reg, semi) sepseq;
terminator : semi option;
closing : closing
map_inj : binding reg injection reg
}
and binding = {
@ -515,12 +508,12 @@ and expr =
| EPar of expr par reg
and set_expr =
SetInj of injection reg
SetInj of expr injection reg
| SetMem of set_membership reg
and injection = {
and 'a injection = {
opening : opening;
elements : (expr, semi) sepseq;
elements : ('a, semi) sepseq;
terminator : semi option;
closing : closing
}
@ -535,7 +528,7 @@ and closing =
and map_expr =
MapLookUp of map_lookup reg
| MapInj of map_injection reg
| MapInj of binding reg injection reg
and map_lookup = {
path : path;
@ -591,7 +584,7 @@ and string_expr =
and list_expr =
Cons of cons bin_op reg
| List of injection reg
| List of expr injection reg
| Nil of nil par reg
and nil = {
@ -1227,10 +1220,10 @@ and print_expr = function
and print_map_expr = function
MapLookUp {value; _} -> print_map_lookup value
| MapInj inj -> print_map_injection inj
| MapInj inj -> print_injection "map" print_binding inj
and print_set_expr = function
SetInj inj -> print_injection "set" inj
SetInj inj -> print_injection "set" print_expr inj
| SetMem mem -> print_set_membership mem
and print_set_membership {value; _} =
@ -1301,7 +1294,7 @@ and print_string_expr = function
and print_list_expr = function
Cons {value = {arg1; op; arg2}; _} ->
print_expr arg1; print_token op "#"; print_expr arg2
| List e -> print_injection "list" e
| List e -> print_injection "list" print_expr e
| Nil e -> print_nil e
and print_constr_expr = function
@ -1350,14 +1343,14 @@ and print_set_patch node =
print_token kwd_patch "patch";
print_path path;
print_token kwd_with "with";
print_injection "set" set_inj
print_injection "set" print_expr set_inj
and print_map_patch node =
let {kwd_patch; path; kwd_with; map_inj} = node in
print_token kwd_patch "patch";
print_path path;
print_token kwd_with "with";
print_map_injection map_inj
print_injection "map" print_binding map_inj
and print_map_remove node =
let {kwd_remove; key; kwd_from; kwd_map; map} = node in
@ -1375,19 +1368,14 @@ and print_set_remove node =
print_token kwd_set "set";
print_path set
and print_map_injection {value; _} =
let {opening; bindings; terminator; closing} = value in
print_opening "map" opening;
print_sepseq ";" print_binding bindings;
print_terminator terminator;
print_closing closing
and print_injection kwd {value; _} =
let {opening; elements; terminator; closing} : injection = value in
print_opening kwd opening;
print_sepseq ";" print_expr elements;
print_terminator terminator;
print_closing closing
and print_injection :
'a.string -> ('a -> unit) -> 'a injection reg -> unit =
fun kwd print {value; _} ->
let {opening; elements; terminator; closing} = value in
print_opening kwd opening;
print_sepseq ";" print elements;
print_terminator terminator;
print_closing closing
and print_opening lexeme = function
Kwd kwd -> print_token kwd lexeme

21
AST.mli
View File

@ -354,21 +354,14 @@ and set_patch = {
kwd_patch : kwd_patch;
path : path;
kwd_with : kwd_with;
set_inj : injection reg
set_inj : expr injection reg
}
and map_patch = {
kwd_patch : kwd_patch;
path : path;
kwd_with : kwd_with;
map_inj : map_injection reg
}
and map_injection = {
opening : opening;
bindings : (binding reg, semi) sepseq;
terminator : semi option;
closing : closing
map_inj : binding reg injection reg
}
and binding = {
@ -499,12 +492,12 @@ and expr =
| EPar of expr par reg
and set_expr =
SetInj of injection reg
SetInj of expr injection reg
| SetMem of set_membership reg
and injection = {
and 'a injection = {
opening : opening;
elements : (expr, semi) sepseq;
elements : ('a, semi) sepseq;
terminator : semi option;
closing : closing
}
@ -519,7 +512,7 @@ and closing =
and map_expr =
MapLookUp of map_lookup reg
| MapInj of map_injection reg
| MapInj of binding reg injection reg
and map_lookup = {
path : path;
@ -575,7 +568,7 @@ and string_expr =
and list_expr =
Cons of cons bin_op reg
| List of injection reg
| List of expr injection reg
| Nil of nil par reg
and nil = {

View File

@ -545,7 +545,7 @@ map_injection:
let region = cover $1 closing
and value = {
opening = Kwd $1;
bindings = Some (first, others);
elements = Some (first, others);
terminator;
closing = End closing}
in {region; value}
@ -554,7 +554,7 @@ map_injection:
let region = cover $1 $2
and value = {
opening = Kwd $1;
bindings = None;
elements = None;
terminator = None;
closing = End $2}
in {region; value}
@ -564,16 +564,16 @@ map_injection:
let region = cover $1 closing
and value = {
opening = KwdBracket ($1,$2);
bindings = Some (first, others);
elements = Some (first, others);
terminator;
closing = RBracket closing}
in {region; value}
}
| Map LBRACKET RBRACKET {
let region = cover $1 $3
and value = {
and value = {
opening = KwdBracket ($1,$2);
bindings = None;
elements = None;
terminator = None;
closing = RBracket $3}
in {region; value}}