Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 
programs.
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:

EXTEND:
    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>>
	in
	<:expr< ATypeConstructor  $b$>>
...
END	

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 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