@@ -14,6 +14,12 @@ let rec lines_of_t t =
1414
1515let string_of_ts ts = String. concat " \n " (List. concat (List. map lines_of_t ts))
1616
17+ let keywords = [
18+ " open" ;
19+ ]
20+
21+ let escape_keywords x = if List. mem x keywords then " _" ^ x else x
22+
1723open Printf
1824
1925let rec typeof ?(expand_aliases =false ) env t =
@@ -315,7 +321,7 @@ let skeleton_method unimplemented env i m =
315321 let unimplemented_error =
316322 sprintf " return (`Error (Unimplemented \" %s.%s\" ))" i.Interface. name m.Method. name in
317323 [
318- Line (sprintf " let %s x =" m.Method. name);
324+ Line (sprintf " let %s x =" (escape_keywords m.Method. name) );
319325 Block [
320326 Line (sprintf " let open Types.%s.%s in" i.Interface. name (String. capitalize m.Method. name));
321327 Line " let open Types in" ;
@@ -365,7 +371,7 @@ let example_stub env is i m =
365371 ];
366372 Line " end)" ;
367373 Line " " ;
368- Line (sprintf " let result = Client.%s %s;;" m.Method. name (String. concat " " (List. map (fun a -> sprintf " ~%s:%s" a.Arg. name (example_value_of env a.Arg. ty)) m.Method. inputs)));
374+ Line (sprintf " let result = Client.%s %s;;" (escape_keywords m.Method. name) (String. concat " " (List. map (fun a -> sprintf " ~%s:%s" a.Arg. name (example_value_of env a.Arg. ty)) m.Method. inputs)));
369375 ]
370376
371377let skeleton_of_interface unimplemented suffix env i =
@@ -381,7 +387,7 @@ let skeleton_of_interface unimplemented suffix env i =
381387let signature_of_interface env i =
382388 let signature_of_method m =
383389 Line (sprintf " val %s: Types.%s.%s.In.t -> (Types.%s.%s.Out.t, exn) Result.t t"
384- m.Method. name
390+ (escape_keywords m.Method. name)
385391 i.Interface. name (String. capitalize m.Method. name)
386392 i.Interface. name (String. capitalize m.Method. name)
387393 ) in
@@ -402,7 +408,7 @@ let server_of_interface env i =
402408 [
403409 Line (sprintf " | Types.%s.In.%s x ->" i.Interface. name (String. capitalize m.Method. name));
404410 Block [
405- Line (sprintf " Impl.%s x" m.Method. name);
411+ Line (sprintf " Impl.%s x" (escape_keywords m.Method. name) );
406412 Line " >>= fun result ->" ;
407413 Line " return (Result.(>>=) result (fun ok ->" ;
408414 Block [
@@ -441,17 +447,17 @@ let server_of_interface env i =
441447let client_of_interfaces env is =
442448 let client_of_method env i m =
443449 [
444- Line (sprintf " let %s_r x =" m.Method. name);
450+ Line (sprintf " let %s_r x =" (escape_keywords m.Method. name) );
445451 Block [
446452 Line (sprintf " let call = Types.%s.In.call_of (Types.%s.In.%s x) in" i.Interface. name i.Interface. name (String. capitalize m.Method. name));
447453 Line " RPC.rpc call >>= fun response ->" ;
448454 Line (sprintf " let result = Result.(>>=) (result_of_response response) (fun x -> Result.return (Types.%s.%s.Out.t_of_rpc x)) in" i.Interface. name (String. capitalize m.Method. name));
449455 Line " return result" ;
450456 ];
451- Line (sprintf " let %s %s =" m.Method. name (String. concat " " (List. map (fun i -> sprintf " ~%s" i.Arg. name) m.Method. inputs)));
457+ Line (sprintf " let %s %s =" (escape_keywords m.Method. name) (String. concat " " (List. map (fun i -> sprintf " ~%s" i.Arg. name) m.Method. inputs)));
452458 Block [
453459 Line (sprintf " let r = Types.%s.%s.In.({ %s }) in" i.Interface. name (String. capitalize m.Method. name) (String. concat " ; " (List. map (fun i -> sprintf " %s = %s" i.Arg. name i.Arg. name) m.Method. inputs)));
454- Line (sprintf " %s_r r" m.Method. name);
460+ Line (sprintf " %s_r r" (escape_keywords m.Method. name) );
455461 ]
456462 ] in
457463 let client_of_interface env i =
0 commit comments