Version française
Home     About     Download     Resources     Contact us    
Browse thread
How to Create Sensible Debugging Information when Dynamically Typechecking Code Generated with camlp5 Quotations
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] How to Create Sensible Debugging Information when Dynamically Typechecking Code Generated with camlp5 Quotations
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/