From 2a9ef440db4b6be39df9b8083835a3fbb4136c37 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Wed, 24 Jun 2020 12:27:09 +0200 Subject: [PATCH] to_json for locations --- src/stages/5-ast_typed/PP_json.ml | 2 +- vendors/ligo-utils/simple-utils/location.ml | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/stages/5-ast_typed/PP_json.ml b/src/stages/5-ast_typed/PP_json.ml index d1430a4e1..0bcddfc32 100644 --- a/src/stages/5-ast_typed/PP_json.ml +++ b/src/stages/5-ast_typed/PP_json.ml @@ -33,7 +33,7 @@ module M = struct packed_internal_operation = (fun _visitor NoState _op -> `String "Operation(...bytes)") ; expression_variable = (fun _visitor NoState ev -> `Assoc ["exp-var", `String (asprintf "%a" Var.pp ev.wrap_content)] ) ; constructor' = (fun _visitor NoState (Constructor c) -> `Assoc ["constructor", `String c] ) ; - location = (fun _visitor NoState loc -> `String (asprintf "%a" Location.pp loc) ) ; (*TODO*) + location = (fun _visitor NoState loc -> Location.pp_json loc) ; label = (fun _visitor NoState (Label lbl) -> `Assoc ["label" , `String lbl] ) ; ast_core_type_expression = (fun _visitor NoState te -> `String (asprintf "%a" (Ast_core.PP.type_expression) te) ) ; (*TODO*) constructor_map = (fun _visitor continue NoState cmap -> diff --git a/vendors/ligo-utils/simple-utils/location.ml b/vendors/ligo-utils/simple-utils/location.ml index 8febf4698..db7af5759 100644 --- a/vendors/ligo-utils/simple-utils/location.ml +++ b/vendors/ligo-utils/simple-utils/location.ml @@ -17,6 +17,18 @@ let pp = fun ppf t -> | Virtual _s -> Format.fprintf ppf "" | File f -> Format.fprintf ppf "%s" (f#to_string `Point) +let pp_json = fun t -> + match t with + | Virtual s -> `Assoc ["virtual" , `String s] + | File f -> + `Assoc [ + ("file", `String f#file) ; + ("from_row", `Int f#start#line) ; + ("from_col", `Int (f#start#column `Point)) ; + ("to_row", `Int f#stop#line) ; + ("to_col", `Int (f#stop#column `Point)) ; + ] + let compare a b = match a,b with | (File a, File b) -> Region.compare a b | (File _, Virtual _) -> -1