From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id AFCEEBBAF for ; Thu, 24 Sep 2009 00:54:23 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArsFAHBDuko+lQkY/2dsb2JhbACBUdVshBsFgVhjhFE X-IronPort-AV: E=Sophos;i="4.44,440,1249250400"; d="scan'208";a="36698356" Received: from colo9-24.users.colocall.net (HELO dragon.mykola.org) ([62.149.9.24]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 24 Sep 2009 00:54:23 +0200 Received: from SOL-FTTB.133.96.27.94.sovam.net.ua (SOL-FTTB.133.96.27.94.sovam.net.ua [94.27.96.133] (may be forged)) (authenticated bits=0) by dragon.mykola.org (8.14.3/8.14.3) with ESMTP id n8NMsJR3013540 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Thu, 24 Sep 2009 01:54:19 +0300 (EEST) (envelope-from nick@mykola.org) Cc: caml-list@yquem.inria.fr Message-Id: From: Mykola Stryebkov To: Richard Jones In-Reply-To: <20090923195713.GA12236@annexia.org> Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Apple Message framework v936) Subject: Re: [Caml-list] Generation of Java code from OCaml Date: Thu, 24 Sep 2009 01:54:20 +0300 References: <46ACB6F9-FFAE-4C9C-9E46-21CA2E93434C@mykola.org> <20090923195713.GA12236@annexia.org> X-Mailer: Apple Mail (2.936) X-Spam: no; 0.00; ocaml:01 ocaml:01 lib:01 translated:01 implements:01 pubkey:01 23,:98 2009:98 blog:98 blog:98 bce:98 W6:98 wrote:01 wrote:01 preprocessor:01 Hi, Richard. On 23 =D0=92=D0=B5=D1=80 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 =20= 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 =3D { order_id : int; order_code : string; order_price : int; ... } ... must be translated in something like: public class CreateOrderResponse extends ... implements ... { private int id =3D 0; private String code =3D ""; private int price =3D 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 =20 generate functions, used to convert records (marked by "json" keyword) to strings in json format and vice versa. --=20 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