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

46
AST.ml
View File

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

21
AST.mli
View File

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

View File

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