Skip to content

Commit

Permalink
#660 Add a term constructor to destinguish algebraic exrpessions from…
Browse files Browse the repository at this point in the history
… strings in json encoding
  • Loading branch information
Jérôme FERET committed May 7, 2023
1 parent 6c80cb2 commit a4a26c1
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions core/term/primitives.ml
Original file line number Diff line number Diff line change
Expand Up @@ -356,20 +356,30 @@ type 'alg_expr print_expr =
| Alg_pexpr of 'alg_expr Locality.annot

let print_expr_to_yojson ~filenames f_mix f_var = function
| Str_pexpr s -> Locality.annot_to_yojson ~filenames JsonUtil.of_string s
| Str_pexpr s ->
Locality.annot_to_yojson ~filenames JsonUtil.of_string s
| Alg_pexpr a ->
Locality.annot_to_yojson ~filenames
(Alg_expr.e_to_yojson ~filenames f_mix f_var) a
`Assoc ["A",Locality.annot_to_yojson ~filenames
(Alg_expr.e_to_yojson ~filenames f_mix f_var) a]


let print_expr_of_yojson ~filenames f_mix f_var x =
try Str_pexpr (Locality.annot_of_yojson
match x with
| `Assoc ["A",x] ->
begin
try Alg_pexpr (Locality.annot_of_yojson
~filenames (Alg_expr.e_of_yojson ~filenames f_mix f_var) x)
with Yojson.Basic.Util.Type_error _ ->
raise (Yojson.Basic.Util.Type_error ("Incorrect print expr",x))
end
| x ->
begin
try Str_pexpr (Locality.annot_of_yojson
~filenames (JsonUtil.to_string ?error_msg:None) x)
with Yojson.Basic.Util.Type_error _ ->
try Alg_pexpr (Locality.annot_of_yojson
~filenames (Alg_expr.e_of_yojson ~filenames f_mix f_var) x)
with Yojson.Basic.Util.Type_error _ ->
raise (Yojson.Basic.Util.Type_error ("Incorrect print expr",x))

with Yojson.Basic.Util.Type_error _ ->
raise (Yojson.Basic.Util.Type_error ("Incorrect print expr",x))
end

let map_expr_print f x =
List.map (function
| Str_pexpr _ as x -> x
Expand Down

0 comments on commit a4a26c1

Please sign in to comment.