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=none autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 307A3BC69 for ; Wed, 19 Dec 2007 10:50:33 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAABd4aEfAXQImh2dsb2JhbACPfQEBAQgKKZh4 X-IronPort-AV: E=Sophos;i="4.24,183,1196636400"; d="scan'208";a="5348092" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 19 Dec 2007 10:50:32 +0100 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id lBJ9oWON022003 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 19 Dec 2007 10:50:32 +0100 X-IronPort-AV: E=Sophos;i="4.24,183,1196636400"; d="scan'208";a="7010637" Received: from yquem.inria.fr ([128.93.8.37]) by mail3-relais-sop.national.inria.fr with ESMTP; 19 Dec 2007 10:50:32 +0100 Received: by yquem.inria.fr (Postfix, from userid 25991) id 57550BC69; Wed, 19 Dec 2007 10:50:32 +0100 (CET) Date: Wed, 19 Dec 2007 10:50:32 +0100 From: Daniel de Rauglaudre To: caml-list@inria.fr Subject: Re: [Caml-list] How to Create Sensible Debugging Information when Dynamically Typechecking Code Generated with camlp5 Quotations Message-ID: <20071219095032.GA4691@yquem.inria.fr> References: <1197733590-sup-3933@ausone.local> <86496.88461.qm@web60123.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <86496.88461.qm@web60123.mail.yahoo.com> User-Agent: Mutt/1.5.9i X-Miltered: at discorde with ID 4768E968.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; rauglaudre:01 rauglaudre:01 camlp:01 expr:01 expr:01 pcaml:01 pcaml:01 wrote:01 dynamically:01 typechecking:01 caml-list:01 functions:01 patt:01 patt:01 int:01 Hi, On Tue, Dec 18, 2007 at 03:05:05PM -0800, echinuz echinuz wrote: > That seems to have done the trick. Thanks for adding that function. > The overall solution is a little awkward, so if you take requests, > it would be nice if this process is streamlined in future versions. > In other words, it would be nice if there was an easier way to pass > through location information into the final AST and an easier way to > throw errors with this information. Ok, but I don't see, for the moment, what kind of function I can offer. In the meantime, you can improve your code by building the functions: let make_expr_loc loc = let line_nb,bol_pos,bp,ep = get_loc loc in <:expr< (Ploc.make $int:line_nb$ $int:bol_pos$ ($int:bp$, $int:ep$), $str:!Pcaml.input_file$) >> ;; let make_patt_loc loc = let line_nb,bol_pos,bp,ep = get_loc loc in <:patt< (Ploc.make $int:line_nb$ $int:bol_pos$ ($int:bp$, $int:ep$), $str:!Pcaml.input_file$) >> ;; and, therefore, your: | PInt (loc,x)-> let line_nb,bol_pos,bp,ep=get_loc loc in <:expr< Alg.Int ( (Ploc.make$int:line_nb$ $int:bol_pos$ ($int:bp$,$int:ep$), $str:!Pcaml.input_file$), $int:x$) >> can be written: | PInt (loc,x)-> <:expr< Alg.Int ($make_expr_loc loc$, $int:x$) >> For antiquotations, notice that you can use named antiquotations. For example, adding a case, in your grammar: | x=ANTIQUOT "int"-> ... allowing you to use $int:expr$ in your quotations, for an expression of type int, and you can generate the good code with Alg.Int and a correctly shifted location (without forgetting the "$int:" before the expression). You can add a case for floats, and so on. -- Daniel de Rauglaudre http://pauillac.inria.fr/~ddr/