From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by yquem.inria.fr (Postfix, from userid 25991) id 53C19BBAF; Thu, 12 Aug 2010 11:06:26 +0200 (CEST) Date: Thu, 12 Aug 2010 11:06:26 +0200 From: Daniel de Rauglaudre To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] camlp5 questions Message-ID: <20100812090626.GA11905@yquem.inria.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Spam: no; 0.00; rauglaudre:01 rauglaudre:01 camlp:01 ocaml:01 toplevel:01 parser:01 compiler:01 toplevel:01 camlp:01 exn:01 ocaml:01 printexc:01 runtime:01 ocaml's:01 equivalently:01 Hi, On Wed, Aug 11, 2010 at 07:45:26PM -0400, Nicolas Ojeda Bar wrote: > 1. When I load my grammar in a suitable Ocaml toplevel, I get > wonderful error messages for the parser, but when I am running > my compiler stand alone, I only get an exception. Is there a > way to recover the error messages that I get when running under > the toplevel for my use? When a Camlp5 grammar entry fails, it raises an exception defined in the Camlp5 module Ploc. This exception encloses the location and the real exception. Do: try Grammar.Entry.parse your_entry with Ploc (loc, exn) -> ... print the location 'loc' of the error if you want using the module Ploc ... print the real exception 'exn' using the OCaml module Printexc or raises it to make the OCaml runtime display it > 2. What is the simplest way of replacing (not extending) Ocaml's > grammar using Camlp5 ? Or equivalently, if I have a parser that > generates Ocaml AST using q_MLast, how do I do to feed that to > the Ocaml compiler? If your grammar is in the file 'foo.ml', compile it with ocamlc. It produces the file 'foo.cmo'. And to compile a file 'bar.ml' using your grammar, do: ocamlc -pp 'camlp5 ./foo.cmo pr_dump.cmo' bar.ml -- Daniel de Rauglaudre http://pauillac.inria.fr/~ddr/