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
[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: 2003-01-08 (02:31)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] type problem with camlp4

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.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: