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] A question about Camlp4
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-04-03 (09:26)
From: Frederic Tronel <Frederic.Tronel@i...>
Subject: [Caml-list] A question about Camlp4
Hi list,

I'm using camlp4 in order to embed a scripting language within my caml 
I've already done this one year ago for a subset of Lotos verification 
language, and I'm extending this work.

I'm facing a difficulty. Here is a canonical example of the problem:

    rule1: ..... ->    <:expr< >>   (* A rule that generate a ML AST *)
    rule2:  OPT a = rule1 ..... ->
	let b = match a with
		None -> <:expr<None>>
		Some x -> <:expr<Some $x>>
	<:expr< ATypeConstructor  $b$>>

I have to do this small trick for each optionnal symbol in each rule, 
(this is also true for list meta symbols introduced by LIST0, LIST1 ...).
It would greatly improve readability of my program, if I could define a 
small function outside from the grammar extension which would do:

optionToAst o =
match o with
  None -> <:expr<None>>
  Some x -> <:expr<Some $x>>

However if I do this the compiler complains about unbound value "loc".
Thanks for your help.

Best regards,

Frederic Tronel.

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