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=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id A098DBBAF for ; Tue, 5 Aug 2008 19:53:11 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEANYvmEjAXQIm/2dsb2JhbACuRw X-IronPort-AV: E=Sophos;i="4.31,311,1215381600"; d="scan'208";a="15744591" Received: from discorde.inria.fr ([192.93.2.38]) by mail3-smtp-sop.national.inria.fr with ESMTP; 05 Aug 2008 19:53:11 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m75HrAOM028172 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 5 Aug 2008 19:53:10 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmIBAGEwmEjBvsFKnWdsb2JhbACRNwEBAQEBCA0HnG0 X-IronPort-AV: E=Sophos;i="4.31,311,1215381600"; d="scan'208";a="15831202" Received: from dnsp.umh.ac.be (HELO hermes.umh.ac.be) ([193.190.193.74]) by mail1-smtp-roc.national.inria.fr with ESMTP; 05 Aug 2008 19:53:10 +0200 Received: from poincare.swapping.umh.ac.be (poincare.swapping.umh.ac.be [10.102.100.47]) by hermes.umh.ac.be (8.14.2/8.13.6) with ESMTP id m75HnxrI233678; Tue, 5 Aug 2008 19:49:59 +0200 Received: from localhost ([127.0.0.1] ident=trch) by poincare.swapping.umh.ac.be with esmtp (Exim 4.69) (envelope-from ) id 1KQQia-0006S2-TF; Tue, 05 Aug 2008 19:53:08 +0200 Date: Tue, 05 Aug 2008 19:53:08 +0200 (CEST) Message-Id: <20080805.195308.265324514001300039.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? From: Christophe TROESTLER In-Reply-To: <20080805160426.GA698@annexia.org> References: <20080805160426.GA698@annexia.org> X-Face: #2fb%mPx>rRL@4ff~TVgZ"<[:,oL"`TUEGK/[8/qb58~C>jR(x4A+v/n)7BgpEtIph_neoLKJBq0JBY9:}8v|j Organization: University of Mons-Hainaut X-Mailer: Mew version 6.0.51 on Emacs 22.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.64 on 193.190.193.76 X-Miltered: at discorde with ID 48989386.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 expr:01 expr:01 christophe:01 troestler:01 christophe:01 troestler:01 ocaml:01 0100,:01 camlp:01 syntax:01 syntax:01 ocaml:01 wrote:01 parsing:01 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