On Mon, Jul 26, 2010 at 8:41 AM, Joel Reymont <[email protected]> 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 _______________________________________________ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
