From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA28216; Thu, 3 Apr 2003 11:40:21 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA28335 for ; Thu, 3 Apr 2003 11:40:20 +0200 (MET DST) Received: from mwinf0302.wanadoo.fr (smtp4.wanadoo.fr [193.252.22.28]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h339eJ514028 for ; Thu, 3 Apr 2003 11:40:19 +0200 (MET DST) Received: from debian (ca-bordeaux-8-246.abo.wanadoo.fr [80.8.80.246]) by mwinf0302.wanadoo.fr (SMTP Server) with ESMTP id 7F0C3C00028D for ; Thu, 3 Apr 2003 11:40:19 +0200 (CEST) Received: from moi by debian with local (Exim 3.36 #1 (Debian)) id 1911DP-0000WF-00 for ; Thu, 03 Apr 2003 11:40:59 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] A question about Camlp4 Mail-Copy-To: never From: Remi Vanicat Date: Thu, 03 Apr 2003 11:40:59 +0200 In-Reply-To: <3E8BFE27.9040602@inrialpes.fr> (Frederic Tronel's message of "Thu, 03 Apr 2003 11:25:59 +0200") Message-ID: <87znn7lxzo.dlv@wanadoo.fr> User-Agent: Gnus/5.090015 (Oort Gnus v0.15) Emacs/21.2 References: <3E8BFE27.9040602@inrialpes.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; caml-list:01 camlp:01 tronel:01 inrialpes:01 lotos:01 expr:01 optionnal:01 compiler:01 caml:01 dept-info:01 labri:01 u-bordeaux:01 writes:01 remi:01 vanicat:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Frederic Tronel writes: > 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> > Some x -> <:expr> > 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> > Some x -> <:expr> > > However if I do this the compiler complains about unbound value "loc". > Thanks for your help. there is an "hidden" loc "argument" to expr quotation, and this loc variable is defined in the action. let optionToAst loc o = match o with | None -> <:expr> | Some x -> <:expr> then you could call "optionToAst loc a" and it will work... -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- 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