Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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

On Fri, Dec 14, 2007 at 01:22:23PM -0800, echinuz echinuz wrote:

> The language, by itself, can be statically type checked, but since I
> allow antiquotations I must type check at runtime.

I don't understand that. Antiquotations do not imply runtime type
checking: they are just syntax.

> let x=... in
> let prog= <:prog<
>      embedded commands...
>      more embedded commands...
> >> in
> execute prog;;
> The problem with location information generated in camlp5 is that it
> gives the location relative to the quote.

If the above program is OCaml+Camlp5 (I mean, not your language with
your syntax and semantics), I don't understand what you say : the
location information is absolutely not relative to the quotation !

But, perhaps, you mean : in error messages, the entire quotation is
underlined even if the message concerns a sub-part of the quotation ?

By defaut, typing errors show the entire quotation, because the
system cannot know where is the precise location of the error,
a quotation being any text. There is no knowledge of the
correspondence between the quotation text and the syntax tree,
and even no guarantee that such a correspondence exists !

For example if the code is :
   <:prog< this is a variable foo >>
and the typing error message is :
   Unbound variable : foo

there is no reason why the variable "foo" would match the text "foo" of
the quotation text. It could be a quotation expander returning
<:expr< foo >> whatever the quotation text. Therefore the OCaml typing
has no reason to underline the text "foo" of the quotation.

This is why the default behaviour of the Camlp5 quotation system
set the entire quotation in the whole syntax tree of the quotation.

If you want to specify a specific location to a part of your quotation,
you have to create specific nodes <:expr< $anti:x$ >> or <:patt< $anti:x$ >>
around these nodes. See the chapter about quotations and the one about
locations in Camlp5 documentation.

If you use Camlp5 extensible grammars to parse your quotation, or parts
of your quotation, you may have your quotation or these parts of your
quotation correctly located, relative to the quotation, and a good usage
of the antiquotation nodes above should give you correct typing error
messages, relative to the entire program.

Location is indeed a difficult part in programming quotations. Bad
programmed, errors can be shown in unexpected parts of the program.
You have to read the documentation and understand exactly what things

Hope this helps.

Daniel de Rauglaudre