caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Mykola Stryebkov <nick@mykola.org>
To: Richard Jones <rich@annexia.org>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Generation of Java code from OCaml
Date: Thu, 24 Sep 2009 01:54:20 +0300	[thread overview]
Message-ID: <B025ECCE-AADF-48A6-8F9B-D5C5D9FAB2E3@mykola.org> (raw)
In-Reply-To: <20090923195713.GA12236@annexia.org>

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  
generate
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






  reply	other threads:[~2009-09-23 22:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-23 18:15 Mykola Stryebkov
2009-09-23 19:57 ` [Caml-list] " Richard Jones
2009-09-23 22:54   ` Mykola Stryebkov [this message]
2009-09-24  8:03     ` David Allsopp
2009-09-24  9:45       ` blue storm
2009-09-24 11:18         ` Martin Jambon
2009-09-24 12:02           ` blue storm
2009-09-24 12:19             ` Martin Jambon
2009-10-03 12:16               ` Anil Madhavapeddy
2009-10-03 17:27                 ` blue storm
2009-10-03 18:29                   ` Anil Madhavapeddy
2009-09-26  7:37             ` ygrek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=B025ECCE-AADF-48A6-8F9B-D5C5D9FAB2E3@mykola.org \
    --to=nick@mykola.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=rich@annexia.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).