English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Generation of Java code from OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-09-23 (22:54)
From: Mykola Stryebkov <nick@m...>
Subject: Re: [Caml-list] Generation of Java code from OCaml
Hi, Richard.

On 23 Вер 2009, at 22:57, Richard Jones wrote:

> On Wed, Sep 23, 2009 at 09:15:08PM +0300, Mykola Stryebkov wrote:
>> I need to generate arbitrary text (more specifically, Java code) from
>> Ocaml structures, pretty similar to how json-static lib generates
>> ocaml code from ocaml structures.
>> Which approach would you recommend?
>> Is it possible to use ocamlp4 for it?
> Do you want to generate valid Java code (or an AST) or just string
> bits of text together?

I'm going to use stringing bits of text together. But text generating  
is not
an issue here. The issue is how to make this stringing driven by
description of ocaml records.

I have few hundreds of types. For each ocaml type I want to generate
corresponding Java class with function (constructor) that initialize an
object of this class from json string. E.g.:

type json create_order_response = {
   order_id : int;
   order_code : string;
   order_price : int;

... must be translated in something like:

public class CreateOrderResponse extends ... implements ... {
	private int id = 0;
	private String code = "";
	private int price = 0;
	public CreateOrderResponse(String json) { ... }

P.S.: I'm using json-static library and its preprocessor module
(http://martin.jambon.free.fr/json-static.html) to automatically  
functions, used to convert records (marked by "json" keyword) to strings
in json format and vice versa.

Mykola Stryebkov
Blog: http://mykola.org/blog/
Public key: http://mykola.org/pubkey.txt
fpr: 0226 54EE C1FF 8636 36EF  2AC9 BCE9 CFC7 9CF4 6747