Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Jan 25, 2024
1 parent ac56d11 commit 15b7c95
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 65 deletions.
4 changes: 2 additions & 2 deletions src/compiler/hxb/hxbWriterConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let create () = {
let error s =
Error.raise_typing_error s null_pos

module WriterConfigReader (API : DataApi.DataApi) = struct
module WriterConfigReader (API : DataReaderApi.DataReaderApi) = struct
let read_target_config config fl =
List.iter (fun (s,data) -> match s with
| "generate" ->
Expand Down Expand Up @@ -71,7 +71,7 @@ module WriterConfigReader (API : DataApi.DataApi) = struct
API.read_optional data read
end

module WriterConfigReaderJson = WriterConfigReader(JsonDataApi)
module WriterConfigReaderJson = WriterConfigReader(JsonDataApi.JsonReaderApi)

let process_json config target_name json =
WriterConfigReaderJson.read_writer_config config target_name json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module type DataApi = sig
module type DataReaderApi = sig
type data

val read_optional : data -> (data -> unit) -> unit
Expand Down
82 changes: 42 additions & 40 deletions src/core/data/jsonDataApi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,45 @@ let error s =
(* TODO: should this raise something else? *)
Error.raise_typing_error s Globals.null_pos

type data = Json.t

let read_optional json f = match json with
| JNull ->
()
| _ ->
f json

let read_object json = match json with
| JObject fl ->
fl
| _ ->
error (Printf.sprintf "Expected JObject, found %s" (string_of_json json))

let read_array json = match json with
| JArray l ->
l
| _ ->
error (Printf.sprintf "Expected JArray, found %s" (string_of_json json))

let read_string json = match json with
| JString s ->
s
| _ ->
error (Printf.sprintf "Expected JString, found %s" (string_of_json json))

let read_int json = match json with
| JInt i ->
i
| _ ->
error (Printf.sprintf "Expected JInt, found %s" (string_of_json json))

let read_bool json = match json with
| JBool b ->
b
| _ ->
error (Printf.sprintf "Expected JBool, found %s" (string_of_json json))

let data_to_string json =
string_of_json json
module JsonReaderApi = struct
type data = Json.t

let read_optional json f = match json with
| JNull ->
()
| _ ->
f json

let read_object json = match json with
| JObject fl ->
fl
| _ ->
error (Printf.sprintf "Expected JObject, found %s" (string_of_json json))

let read_array json = match json with
| JArray l ->
l
| _ ->
error (Printf.sprintf "Expected JArray, found %s" (string_of_json json))

let read_string json = match json with
| JString s ->
s
| _ ->
error (Printf.sprintf "Expected JString, found %s" (string_of_json json))

let read_int json = match json with
| JInt i ->
i
| _ ->
error (Printf.sprintf "Expected JInt, found %s" (string_of_json json))

let read_bool json = match json with
| JBool b ->
b
| _ ->
error (Printf.sprintf "Expected JBool, found %s" (string_of_json json))

let data_to_string json =
string_of_json json
end
42 changes: 22 additions & 20 deletions src/macro/eval/evalDataApi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@ open EvalValue
open EvalContext
open EvalDecode

type data = value
module EvalReaderApi = struct
type data = value

let read_optional v f = match v with
| VNull ->
()
| _ ->
f v
let read_optional v f = match v with
| VNull ->
()
| _ ->
f v

let read_object v =
List.map (fun (i,v) ->
EvalHash.rev_hash i,v
) (object_fields (decode_object v))
let read_object v =
List.map (fun (i,v) ->
EvalHash.rev_hash i,v
) (object_fields (decode_object v))

let read_array v =
EvalArray.to_list (decode_varray v)
let read_array v =
EvalArray.to_list (decode_varray v)

let read_string v =
decode_string v
let read_string v =
decode_string v

let read_int v =
decode_int v
let read_int v =
decode_int v

let read_bool v =
decode_bool v
let read_bool v =
decode_bool v

let data_to_string v =
(EvalPrinting.s_value 0 v).sstring
let data_to_string v =
(EvalPrinting.s_value 0 v).sstring
end
3 changes: 1 addition & 2 deletions src/typing/macroContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module Interp = struct
end


module HxbWriterConfigReaderJson = HxbWriterConfig.WriterConfigReader(EvalDataApi)
module HxbWriterConfigReaderJson = HxbWriterConfig.WriterConfigReader(EvalDataApi.EvalReaderApi)

let macro_interp_cache = ref None

Expand Down Expand Up @@ -311,7 +311,6 @@ let make_macro_com_api com mcom p =
set_hxb_writer_config = (fun v ->
match com.hxb_writer_config with
| Some config ->
print_endline "READING CONFIG!!!";
HxbWriterConfigReaderJson.read_writer_config config (platform_name com.platform) v
| None ->
()
Expand Down

0 comments on commit 15b7c95

Please sign in to comment.