Browse thread
How to Create Sensible Debugging Information when Dynamically Typechecking Code Generated with camlp5 Quotations
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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 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/