caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jake Donham <jake@donham.org>
To: Joel Reymont <joelr1@gmail.com>
Cc: Nicolas Pouillard <nicolas.pouillard@gmail.com>,
	"caml-list@yquem.inria.fr" <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] [Camlp4] Quotation expander with OCaml syntax
Date: Mon, 26 Jul 2010 09:05:04 -0700	[thread overview]
Message-ID: <AANLkTinkgxjbP9KrZtvoN0GbBYfu8Csesw6jnsgrK=zD@mail.gmail.com> (raw)
In-Reply-To: <9828C252-847B-4921-902D-376412CD7F16@gmail.com>

On Mon, Jul 26, 2010 at 8:41 AM, Joel Reymont <joelr1@gmail.com> wrote:
> What if the quotation is not valid OCaml syntax, e.g. C#, and a Camlp4 parser for it exists?
>
> How would I tie it all together to parse the quotation, plug in  antiquotations and end up with the custom AST that my parser outputs?

There is an example of this in the jslib library in ocamljs:

  http://github.com/jaked/ocamljs/tree/master/src/jslib/

and a somewhat simpler one for JSON here:

  http://github.com/jaked/cufp-metaprogramming-tutorial/tree/master/ocaml/json_quot/

I hope to post a full explanation of this shortly. The magic is the
Camlp4MetaGenerator filter, which generates functions to "lift" your
custom AST into the OCaml AST, either as an expr or a patt. So e.g.
your custom constructor Foo becomes ExId (_, IdUid (_, "Foo"))
(respectively PaId). When you write <:lang< foo >> (where "foo" parses
to Foo) in an expression, you get Foo in the expanded OCaml AST.

Jake


  reply	other threads:[~2010-07-26 16:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <AANLkTikuoN4H0Hsx74JwW66J9jmtq+usDxtQPpYfSGbd@mail.gmail.com>
2010-07-26 14:41 ` Raphael Proust
2010-07-26 15:13   ` [Caml-list] " Nicolas Pouillard
2010-07-26 15:41     ` Joel Reymont
2010-07-26 16:05       ` Jake Donham [this message]
2010-07-26 15:41     ` Raphael Proust
2010-07-26 16:27       ` Nicolas Pouillard
2010-07-26 16:30       ` Jake Donham
2010-07-27  7:57         ` Raphael Proust
2010-07-26 20:08   ` bluestorm
2010-07-26 20:53     ` Raphael Proust
2010-07-27 13:22   ` Thomas.Gazagnaire
2010-07-27 14:38     ` Raphael Proust
2010-07-27 14:47     ` Vincent Balat

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='AANLkTinkgxjbP9KrZtvoN0GbBYfu8Csesw6jnsgrK=zD@mail.gmail.com' \
    --to=jake@donham.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=joelr1@gmail.com \
    --cc=nicolas.pouillard@gmail.com \
    /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).