Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] type problem with camlp4
[ 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] type problem with camlp4
Hi,

On Wed, Jan 08, 2003 at 09:34:55AM +1100, Pietro Abate wrote:

> 	[[ n = STRING ->
> 		let node = magic_function ( parse_string n ) in
> 		let id = gen_id() in
> 		(<:patt<$lid:id$>>,<:expr<$node$>>)
> 	]];
> 
> who can I do that ? what is the magic function ?

let node = Grammar.Entry.parse Pcaml.expr (Stream.of_string n) in

You may need to enclose that with a good "try..with" in case of syntax
error in your string, because the error location raised would be relative
to it, and would highlight a wrong position. Moreover, the resulting
tree should be also re-located in case of semantic error for the
same reason.

Actually, it should be like the handling of quotations, but with that
above function as expander. But the code doing that in Camlp4 is in
several parts and may not be so easy to extract if you don't know the
internal code of Camlp4. I can do it if you want and possibly add a
new function in Camlp4 (module Pcaml) for that kind of usage.

-- 
Daniel de RAUGLAUDRE
http://cristal.inria.fr/~ddr/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners