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 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 054A4BC69 for ; Sun, 16 Dec 2007 17:50:33 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAMvlZEfAXQInh2dsb2JhbACQBQIBCAopl2o X-IronPort-AV: E=Sophos;i="4.24,174,1196636400"; d="scan'208";a="20374679" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 16 Dec 2007 17:50:32 +0100 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id lBGGoVoc002242 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Sun, 16 Dec 2007 17:50:32 +0100 X-IronPort-AV: E=Sophos;i="4.24,174,1196636400"; d="scan'208";a="6885096" Received: from yquem.inria.fr ([128.93.8.37]) by mail3-relais-sop.national.inria.fr with ESMTP; 16 Dec 2007 17:50:31 +0100 Received: by yquem.inria.fr (Postfix, from userid 25991) id 6D417BC69; Sun, 16 Dec 2007 17:50:31 +0100 (CET) Date: Sun, 16 Dec 2007 17:50:31 +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: <20071216165031.GA21572@yquem.inria.fr> References: <1197733590-sup-3933@ausone.local> <266122.53415.qm@web60121.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <266122.53415.qm@web60121.mail.yahoo.com> User-Agent: Mutt/1.5.9i X-Miltered: at concorde with ID 47655757.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; rauglaudre:01 rauglaudre:01 camlp:01 parser:01 checker:01 ocamlc:01 -pp:01 camlp:01 ledit:01 ocaml:01 cmo:01 toplevel:01 uncaught:01 syntax:01 lident:01 Hi, On Sat, Dec 15, 2007 at 11:32:55AM -0800, echinuz echinuz wrote: > Allow me to clarify what I meant by type errors and antiquotations. > Here is a very simple program that contains the parser, type > checker, and quotation generator: After having tested your program, I indeed see: $ ocamlc -pp camlp5o -I +camlp5 -c toto.ml $ ledit ocaml -I +camlp5 camlp5o.cma ./toto.cmo Objective Caml version ... Camlp5 Parsing version ... # <:exp< add(3) >>;; Toplevel input: # <:exp< add(3) >>;; ^^^^^^^^^^^^^^^^ While expanding quotation "exp": Uncaught exception: Toto.TypeError Would you like that only "add" be underlined ? It is possible. You miss information of the location in your syntax tree. I suggest to change your type "palg", on the constructor "PApp" like this: | PApp of string*Ploc.t*palg list where the 2nd argument is the location of the function represented by the string (1st argument). The grammar rule for reading a function with arguments could be changed into: | (f,floc) = lident; "("; xs=LIST1 SELF SEP ","; ")"-> PApp (f,floc,xs)]]; needing an extra rule, "lident", where the location of the identifier is recorded: lident: [[x = LIDENT -> (x, loc)]]; Change the rest of your program to fix the fact that PApp has now three arguments instead of two. In the function "type_expr", the case: | PApp (f,args) -> becomes: | PApp (f,loc,args) -> And the following typing error: if List.length args != 2 then raise TypeError becomes: if List.length args != 2 then Ploc.raise loc TypeError Recompile and test: $ ocamlc -pp camlp5o -I +camlp5 -c toto.ml $ ledit ocaml -I +camlp5 camlp5o.cma ./toto.cmo Objective Caml version ... Camlp5 Parsing version ... # <:exp< add(3) >>;; Toplevel input: # <:exp< add(3) >>;; ^^^ While expanding quotation "exp": Uncaught exception: Toto.TypeError Does it answer your problem ? -- Daniel de Rauglaudre http://pauillac.inria.fr/~ddr/