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 NAA19674; Wed, 9 Oct 2002 13:53:17 +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 NAA19047 for ; Wed, 9 Oct 2002 13:53:16 +0200 (MET DST) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g99BrF517855 for ; Wed, 9 Oct 2002 13:53:15 +0200 (MET DST) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id NAA02494 for caml-list@inria.fr; Wed, 9 Oct 2002 13:53:15 +0200 Date: Wed, 9 Oct 2002 13:53:15 +0200 From: Daniel de Rauglaudre To: caml-list@inria.fr Subject: Re: [Caml-list] Caml4p... help Message-ID: <20021009135315.E1703@verdot.inria.fr> References: <20021009015023.GA10937@zed> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20021009015023.GA10937@zed>; from abate@discus.anu.edu.au on Wed, Oct 09, 2002 at 11:50:23AM +1000 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Wed, Oct 09, 2002 at 11:50:23AM +1000, Pietro Abate wrote: > 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 |] According to your 2nd message, you need a "let" at toplevel, not a "let..in". In this case, it is not "expr" that you must extend but "str_item": indeed, the "let" at toplevel is a structure item, not an expression. > ocamlc -c -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I /usr/lib/ocaml/camlp4 str.ml > File "str.ml", line 18, characters 2-10: > This expression has type unit but is here used with type MLast.expr Like Jeff Henrikson said, it is due to the extraneous "|" in the first rule of "str": you must not put one. It is interpreted as an empty rule, returning "()". I recognize that it is a pitfall of the syntax of EXTEND. A remark: the definition of your type "kind" is unuseful in this file. It will be useful only in the files using this syntax extension. For the LINDENT, instead of LIDENT, this is not detected at compile time, but when you use your syntax expander by "camlp4o ./str.cmo" it displays: Lexer initialization error: - the constructor "LINDENT" is not recognized by Plexer Uncaught exception: Failure("Grammar.extend") In Jeff's answer the #load "camlp4o.cma";; at the beginning of the file is unuseful: Camlp4 knows that it is camlp4. On the other hand, the other loads "q_MLast.cmo" and "pa_extend.cmo" are good and useful, since they allow you to compile your file just with "-pp camlp4o". Here is my version of your file (tested): ---------------------------------------- #load "pa_extend.cmo";; #load "q_MLast.cmo";; open Pcaml;; let str = Grammar.Entry.create gram "str";; EXTEND str_item: [ [ "str"; n = LIDENT; ":"; s = str -> <:str_item< value $lid:n$ = $s$ >> ] ]; str: [ [ n = LIDENT -> <:expr<`Rule $str:n$>> | "["; s = LIST1 str SEP ";"; "]" -> <:expr<`Forall [|$list:s$|] >> | "{"; s = LIST1 str SEP ";"; "}" -> <:expr<`First [|$list:s$|] >> ] ]; END;; ---------------------------------------- -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- 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