From: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] How to Create Sensible Debugging Information when Dynamically Typechecking Code Generated with camlp5 Quotations
Date: Sun, 16 Dec 2007 17:50:31 +0100 [thread overview]
Message-ID: <20071216165031.GA21572@yquem.inria.fr> (raw)
In-Reply-To: <266122.53415.qm@web60121.mail.yahoo.com>
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/
next prev parent reply other threads:[~2007-12-16 16:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-14 21:22 echinuz echinuz
2007-12-15 15:47 ` [Caml-list] " Nicolas Pouillard
2007-12-15 19:32 ` echinuz echinuz
2007-12-16 16:50 ` Daniel de Rauglaudre [this message]
2007-12-17 10:54 ` Nicolas Pouillard
2007-12-17 3:29 ` echinuz echinuz
2007-12-17 5:28 ` Daniel de Rauglaudre
2007-12-17 9:11 ` echinuz echinuz
2007-12-17 12:41 ` Daniel de Rauglaudre
2007-12-18 23:05 ` echinuz echinuz
2007-12-19 9:50 ` Daniel de Rauglaudre
2007-12-15 16:54 ` Daniel de Rauglaudre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071216165031.GA21572@yquem.inria.fr \
--to=daniel.de_rauglaudre@inria.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox