caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* camlp5 questions
@ 2010-08-11 23:45 Nicolas Ojeda Bar
  2010-08-12  9:06 ` [Caml-list] " Daniel de Rauglaudre
  2010-08-12 15:02 ` Daniel de Rauglaudre
  0 siblings, 2 replies; 3+ messages in thread
From: Nicolas Ojeda Bar @ 2010-08-11 23:45 UTC (permalink / raw)
  To: caml-list

Hello,

I am using Camlp5's extensible grammars to parse a language
of my own (no relation at all with Ocaml's). I have some questions
that the manual doesn't seem to address and I was wondering how
to do:

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?

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?

Thanks!
N


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] camlp5 questions
  2010-08-11 23:45 camlp5 questions Nicolas Ojeda Bar
@ 2010-08-12  9:06 ` Daniel de Rauglaudre
  2010-08-12 15:02 ` Daniel de Rauglaudre
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel de Rauglaudre @ 2010-08-12  9:06 UTC (permalink / raw)
  To: caml-list

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/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] camlp5 questions
  2010-08-11 23:45 camlp5 questions Nicolas Ojeda Bar
  2010-08-12  9:06 ` [Caml-list] " Daniel de Rauglaudre
@ 2010-08-12 15:02 ` Daniel de Rauglaudre
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel de Rauglaudre @ 2010-08-12 15:02 UTC (permalink / raw)
  To: Nicolas Ojeda Bar; +Cc: caml-list

Hi,

> 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?

I added a (small) chapter about how to make one's syntax for OCaml
using Camlp5. This chapter will be in next version (5.16) but you
can see it there:
   http://pauillac.inria.fr/~ddr/camlp5/doc/html/redef.html

For the current Camlp5 version (5.15), this part works except that
you have to compile the file "mysyntax.ml" (of that chapter) by:
    ocamlc -pp "camlp5r pa_extend.cmo q_MLast.cmo" -I $(camlp5 -where) -c mysyntax.ml

-- 
Daniel de Rauglaudre
http://pauillac.inria.fr/~ddr/


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-08-12 15:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-11 23:45 camlp5 questions Nicolas Ojeda Bar
2010-08-12  9:06 ` [Caml-list] " Daniel de Rauglaudre
2010-08-12 15:02 ` Daniel de Rauglaudre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).