From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 02E89BC84 for ; Wed, 30 Mar 2005 11:37:44 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2U9bhaE031835 for ; Wed, 30 Mar 2005 11:37:43 +0200 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 LAA25509 for ; Wed, 30 Mar 2005 11:37:43 +0200 (MET DST) Received: from tcs.inf.tu-dresden.de (tcs.inf.tu-dresden.de [141.76.75.101]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2U9bgUA031832 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Wed, 30 Mar 2005 11:37:42 +0200 Received: from ithif59.inf.tu-dresden.de (ithif59 [141.76.75.59]) by tcs.inf.tu-dresden.de (8.12.9/8.12.9) with ESMTP id j2U9bf9E017894 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 30 Mar 2005 11:37:41 +0200 (MET DST) Received: from tews by ithif59.inf.tu-dresden.de with local (Exim 4.44) id 1DGZdt-0006Fj-O2 for caml-list@inria.fr; Wed, 30 Mar 2005 11:37:41 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] passing argument in campl4 ? References: <20050324052918.GA30200@pulp.anu.edu.au> From: Hendrik Tews Date: 30 Mar 2005 11:37:41 +0200 In-Reply-To: <20050324052918.GA30200@pulp.anu.edu.au> Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Scanned-By: MIMEDefang 2.33 (www . roaringpenguin . com / mimedefang) at tcs.inf.tu-dresden.de X-Miltered: at nez-perce with ID 424A7367.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 424A7366.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 hendrik:01 tews:01 tews:01 anu:01 val:01 syntax:01 syntax:01 grammar:01 grammar:01 parser:01 token:01 ocaml:01 parser:01 expr:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: Pietro Abate writes: aa: [[ "AA"; c = bb "val" -> "aa"^c ]]; to bb arg: [[ a = INT; "BB" -> a ]]; The camlp4 reference manual (http://caml.inria.fr/pub/docs/manual-camlp4/manual005.html) says the syntax of a rule is { pattern = } symbol ; ... { pattern = } symbol { -> action } so you can't pass an argument to bb. I can think two possible solutions: 1. Extend the camlp4 syntax for grammar extentions with a new metasymbol "bb" that takes one argument, similar to the metasymbols LIST0 and LIST1 2. Use something like aa: [[ x = do_the_aa_rule -> ... ]] with let do_the_aa_rule = Grammar.Entry.of_parser gram "do_the_aa_rule" (* a (Token.t Stream.t -> 'a) function, where 'a is the type of x above *) The ocaml parser distributed with camlp4 contains examples for the latter technique, see for instance infixop0 or test_label_eq in camlp4/etc/pa_o.ml. Further, these sources seem to indicate that there is no nice solution to your problem: The levels "||" to "**" of the entry expr could benefit from some more abstraction. Bye, Hendrik