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 FAA04187; Wed, 9 Oct 2002 05:35:15 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id FAA04212 for ; Wed, 9 Oct 2002 05:35:14 +0200 (MET DST) Received: from c007.snv.cp.net (h014.c007.snv.cp.net [209.228.33.242]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id g993ZDD15393 for ; Wed, 9 Oct 2002 05:35:13 +0200 (MET DST) Received: (cpmta 7315 invoked from network); 8 Oct 2002 20:35:10 -0700 Received: from 65.187.194.217 (HELO localhost) by smtp.directvinternet.com (209.228.33.242) with SMTP; 8 Oct 2002 20:35:10 -0700 X-Sent: 9 Oct 2002 03:35:10 GMT Date: Tue, 8 Oct 2002 23:35:08 -0400 Subject: Re: [Caml-list] Caml4p... help Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v482) Cc: To: Pietro Abate From: jehenrik In-Reply-To: <20021009015023.GA10937@zed> Message-Id: <1BC7BF40-DB38-11D6-8FB2-00039375801A@yahoo.com> Content-Transfer-Encoding: 7bit X-Mailer: Apple Mail (2.482) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I've just started playing with Caml4p today and I'm already at a dead > end. My goal is to transform this syntax > > str pc : [a;b;c] > > into a declaration like that. > let pc_str = `Forall [| `Rule a; `Rule b; `Rule c |] Your implementation is basically right, but it has a couple of small errors. Superficially, LINDENT should be LIDENT. Change both of those. You have an extraneous "|" symbol after str: [[. Fix that. The harder to see mistake is that you accidentally name your entry "str" while simultaneously redefining it to be a keyword. This is bad. So change the name of your entry, for example. Say "strentry" instead of str. Then it works: (this has some modifications to run in the toplevel) #load "camlp4o.cma";; #load "q_MLast.cmo";; #load "pa_extend.cmo";; open Pcaml;; type kind = [ | `Rule of string | `First of kind array | `Forall of kind array ] ;; let strentry = Grammar.Entry.create gram "str" ;; EXTEND expr: AFTER "top" [[ "str"; n = LIDENT; ":"; s = strentry -> <:expr< let $lid:n$ = $s$ in $lid:n$ >> ]]; strentry: [[ n = LIDENT -> <:expr<`Rule $str:n$>> | "["; s = LIST1 strentry SEP ";"; "]" -> <:expr<`Forall [|$list:s$|] >> | "{"; s = LIST1 strentry SEP ";"; "}" -> <:expr<`First [|$list:s$|] >> ]]; END;; str pc : [a;b;c];; # - : _[> `Forall of _[> `Rule of string] array] = `Forall [|`Rule "a"; `Rule "b"; `Rule "c"|] Good luck with your project and welcome to the world of camlp4! Jeff Henrikson On Tuesday, October 8, 2002, at 09:50 PM, Pietro Abate wrote: > (*pp camlp4o pa_extend.cmo q_MLast.cmo *) > open Pcaml;; > > type kind = [ > |`Rule of string > |`First of kind array > |`Forall of kind array > ] > > let str = Grammar.Entry.create gram "str";; > > EXTEND > expr: AFTER "top" > [[ "str"; n = LINDENT; ":"; s = str -> > <:expr< let $lid:n$ = $s$ in $lid:n$ >> ]]; > > str: [[ > | n = LINDENT -> <:expr<`Rule $str:n$>> > | "["; s = LIST1 str SEP ";"; "]" -> <:expr<`Forall [|$list:s$|] >> > | "{"; s = LIST1 str SEP ";"; "}" -> <:expr<`First > [|$list:s$|] >> ]]; > > END;; ------------------- 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