@@ -14,6 +14,12 @@ let rec lines_of_t t =
14
14
15
15
let string_of_ts ts = String. concat " \n " (List. concat (List. map lines_of_t ts))
16
16
17
+ let keywords = [
18
+ " open" ;
19
+ ]
20
+
21
+ let escape_keywords x = if List. mem x keywords then " _" ^ x else x
22
+
17
23
open Printf
18
24
19
25
let rec typeof ?(expand_aliases =false ) env t =
@@ -315,7 +321,7 @@ let skeleton_method unimplemented env i m =
315
321
let unimplemented_error =
316
322
sprintf " return (`Error (Unimplemented \" %s.%s\" ))" i.Interface. name m.Method. name in
317
323
[
318
- Line (sprintf " let %s x =" m.Method. name);
324
+ Line (sprintf " let %s x =" (escape_keywords m.Method. name) );
319
325
Block [
320
326
Line (sprintf " let open Types.%s.%s in" i.Interface. name (String. capitalize m.Method. name));
321
327
Line " let open Types in" ;
@@ -365,7 +371,7 @@ let example_stub env is i m =
365
371
];
366
372
Line " end)" ;
367
373
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)));
369
375
]
370
376
371
377
let skeleton_of_interface unimplemented suffix env i =
@@ -381,7 +387,7 @@ let skeleton_of_interface unimplemented suffix env i =
381
387
let signature_of_interface env i =
382
388
let signature_of_method m =
383
389
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)
385
391
i.Interface. name (String. capitalize m.Method. name)
386
392
i.Interface. name (String. capitalize m.Method. name)
387
393
) in
@@ -402,7 +408,7 @@ let server_of_interface env i =
402
408
[
403
409
Line (sprintf " | Types.%s.In.%s x ->" i.Interface. name (String. capitalize m.Method. name));
404
410
Block [
405
- Line (sprintf " Impl.%s x" m.Method. name);
411
+ Line (sprintf " Impl.%s x" (escape_keywords m.Method. name) );
406
412
Line " >>= fun result ->" ;
407
413
Line " return (Result.(>>=) result (fun ok ->" ;
408
414
Block [
@@ -441,17 +447,17 @@ let server_of_interface env i =
441
447
let client_of_interfaces env is =
442
448
let client_of_method env i m =
443
449
[
444
- Line (sprintf " let %s_r x =" m.Method. name);
450
+ Line (sprintf " let %s_r x =" (escape_keywords m.Method. name) );
445
451
Block [
446
452
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));
447
453
Line " RPC.rpc call >>= fun response ->" ;
448
454
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));
449
455
Line " return result" ;
450
456
];
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)));
452
458
Block [
453
459
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) );
455
461
]
456
462
] in
457
463
let client_of_interface env i =
0 commit comments