From: Christophe TROESTLER <Christophe.Troestler+ocaml@umh.ac.be>
To: rich@annexia.org
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] [camlp4] expr_of_string, string_of_expr functions exist?
Date: Tue, 05 Aug 2008 19:53:08 +0200 (CEST) [thread overview]
Message-ID: <20080805.195308.265324514001300039.Christophe.Troestler+ocaml@umh.ac.be> (raw)
In-Reply-To: <20080805160426.GA698@annexia.org>
On Tue, 5 Aug 2008 17:04:26 +0100, Richard Jones wrote:
>
> Maybe a simple question, but does camlp4 have functions to turn
> expr and patt AST structures to and from strings?
Parsing:
open Camlp4.PreCast
let loc = Loc.ghost;;
Syntax.AntiquotSyntax.parse_expr loc "x = 1";;
Syntax.AntiquotSyntax.parse_patt loc "Failure _";;
Printing: I do not know a way to print to a string, only to a file.
I guess this asymmetry is due to the fact that a string output was
never needed... (but it would be useful to me too!) Moreover, you can
only print str_item's, so you have to wrap your expr and patt. E.g.
let e = <:expr< 1 + 1 >>;;
Printers.OCaml.print_implem ~output_file:"/tmp/o.ml" <:str_item< $exp: e$ >>;;
(* will print
let _ = 1 + 1;;
*)
Printers.OCaml.print_implem ~output_file:"/tmp/o.ml"
(let _loc = Ast.loc_of_expr e in Ast.StExp(_loc, e));;
(* will print
1 + 1;;
(but I do not know whether this is a feature!) *)
Hope it helps,
ChriS
next prev parent reply other threads:[~2008-08-05 17:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-05 16:04 Richard Jones
2008-08-05 17:43 ` [Caml-list] " Yitzhak Mandelbaum
2008-08-05 17:53 ` Christophe TROESTLER [this message]
2008-08-06 13:40 ` Richard Jones
2008-08-06 19:58 ` Jeremy Yallop
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=20080805.195308.265324514001300039.Christophe.Troestler+ocaml@umh.ac.be \
--to=christophe.troestler+ocaml@umh.ac.be \
--cc=caml-list@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