If some kind of error happens while compiling a quotation, Camlp4 or Objective Caml display an error message, which shows the source position of the error. By default, the error message highlights the whole quotation, but a quotation expander can specify more precise ``locations'' while parsing and generating its returning string.
A ``location'' is a couple of integers: the first one is the position of the first character of the concerned text, the second one the position of the first character after the concerned text.
To raise an exception in an expander, it is possible to use the
function ``Stdpp.raise_with_loc'' instead of ``raise'',
this first function having a supplementary parameter which is the
location of the error relative to the begin of the quotation.
A problem can arise in string expanders (those returning strings). The resulting string may hold syntax errors. In this case, for there is no ``input location'' for the error, and it is not directly possible to see this error.
To solve this problem, a special option of Camlp4 can be used:
``-QD'' (see the manual page). It is also possible to set the
variable ``Pcaml.quotation_dump_file'' (see section
6.3). The offending string is
then written in a file (whose name is specified by this option or this
variable) and the error message gives the location of the error in
this file.
This problem cannot arise in syntax trees expanders, for there is no parsing following the expansion.
Plexer), is:
location_directive ::= $ int :
string $ |
The int value is the source location of the first character of the antiquotation, relative to the beginning of the quotation string. The string is the antiquotation itself.