aboutsummaryrefslogtreecommitdiff
path: root/discocaml/main.ml
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-01-18 10:58:36 -0600
committerNathan Ringo <nathan@remexre.com>2024-01-18 10:58:36 -0600
commit00d0bfced902e97eeae5257c14134d4bc7efc710 (patch)
treeee026f328614e03aec3ed373d9f2e6c8e255f834 /discocaml/main.ml
parent7017762a4a38266aa88976be141f7bd663647edc (diff)
Commands to interact with discocaml, associated IPC.
Diffstat (limited to 'discocaml/main.ml')
-rw-r--r--discocaml/main.ml27
1 files changed, 23 insertions, 4 deletions
diff --git a/discocaml/main.ml b/discocaml/main.ml
index 2cc97b5..d9895f1 100644
--- a/discocaml/main.ml
+++ b/discocaml/main.ml
@@ -1,3 +1,14 @@
+type command = [ `Roundtrip ]
+
+let command_of_yojson = function
+ | `String "Roundtrip" -> Ok `Roundtrip
+ | _ -> Error "invalid command"
+
+type request = { expr : string; command : command }
+[@@deriving of_yojson { exn = true }]
+
+type response = [ `Error of string ] [@@deriving to_yojson { exn = true }]
+
(*
type position = [%import: Lexing.position] [@@deriving show]
@@ -14,14 +25,22 @@ type structure_item_desc = [%import: Parsetree.structure_item_desc]
type structure_item = [%import: Parsetree.structure_item] [@@deriving show]
type structure = [%import: Parsetree.structure] [@@deriving show]
type toplevel_phrase = [%import: Parsetree.toplevel_phrase] [@@deriving show]
-*)
let parse ~path (src : string) =
let buf = Lexing.from_string src in
buf.lex_start_p <- { buf.lex_start_p with pos_fname = path };
buf.lex_curr_p <- { buf.lex_curr_p with pos_fname = path };
- Parse.use_file buf
+ Parse.expression buf
+
+let () =
+ parse ~path:"main.ml" " print_endline ((\"Hello, world!\") )"
+ |> Format.fprintf Format.std_formatter "\n%a\n" Pprintast.expression
+*)
+
+let handle_request { expr; command } : response =
+ match command with `Roundtrip -> `Error ("TODO: " ^ expr)
let () =
- parse ~path:"main.ml" "let () = print_endline ((\"Hello, world!\") )"
- |> List.iter (Pprintast.toplevel_phrase Format.std_formatter)
+ Yojson.Safe.from_channel stdin
+ |> request_of_yojson_exn |> handle_request |> response_to_yojson
+ |> Yojson.Safe.to_channel stdout