From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 67C9ABB83 for ; Sun, 17 Sep 2006 09:22:51 +0200 (CEST) Received: from mail.rsise.anu.edu.au (mail.rsise.anu.edu.au [150.203.208.4]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id k8H7Mlbx003273 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 17 Sep 2006 09:22:50 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.rsise.anu.edu.au (Postfix) with ESMTP id 8BF94543D6 for ; Sun, 17 Sep 2006 17:22:36 +1000 (EST) Received: from mail.rsise.anu.edu.au ([150.203.208.4]) by localhost (mail [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 19529-02 for ; Sun, 17 Sep 2006 17:22:36 +1000 (EST) Received: from pulp.rsise.anu.edu.au (pulp.rsise.anu.edu.au [150.203.208.49]) by mail.rsise.anu.edu.au (Postfix) with ESMTP id 6FF275430B for ; Sun, 17 Sep 2006 17:22:33 +1000 (EST) Received: by pulp.rsise.anu.edu.au (Postfix, from userid 1560) id 39C9AA0AFC7; Sun, 17 Sep 2006 17:22:42 +1000 (EST) Date: Sun, 17 Sep 2006 17:22:42 +1000 From: Pietro Abate To: ocaml ml Subject: combining camlp4 extensions Message-ID: <20060917072242.GA26895@pulp.rsise.anu.edu.au> Mail-Followup-To: Pietro Abate , ocaml ml MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Operating-System: GNU/Linux X-Organization: Research School of Information Science and Engineering (Australian National University) User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at mail.rsise.anu.edu.au X-Miltered: at discorde with ID 450CF7C7.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; camlp:01 pcaml:01 grammar:01 pcaml:01 expr:01 grammar:01 expr:01 camlp:01 ocamlc:01 -pp:01 cmo:01 mlast:01 cmo:01 ocamlc:01 -pp:01 hi all, In my project I've multiple similar (independent) extensions. These all share a common part. In order to avoid code duplication (I don't want to duplicate the common part in every and each extension), I'm trying to split them in different modules and then generate one library for each extensions by linking the common part with each module. I've cooked up a small example to explain my idea. I've 3 files: ext_repeat.ml and repeat.ml and main.ml ------------ ext_repeat.ml open Pcaml let reexpr = Grammar.Entry.create Pcaml.gram "reexpr";; let extend () = EXTEND GLOBAL: reexpr; reexpr: [[ e = expr -> e ]]; END ;; ----------- -----------repeat.ml open Pcaml let reexpr = Grammar.Entry.create Pcaml.gram "reexpr";; let extend () = EXTEND GLOBAL: reexpr expr ; expr: LEVEL "expr1" [[ "repeat"; e1 = reexpr; "until"; e2 = expr -> <:expr< do { $e1$; while not $e2$ do { $e1$; } } >> ]]; reexpr: [[]]; END ;; -------------- -----------main.ml let main () = Repeat.extend (); Ext_repeat.extend (); in main () ----------- repeat contains a modified version of the canonical repeat example found in the camlp4 manual (the common part). The ext_repeat contains a small extension that is mean to complement the extension defined in the repeat module (the extension part that differ. I can have many of these in my project). The main file is just a device to fire up these extensions. I compile them with: ocamlc -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I +camlp4 -c repeat.ml ocamlc -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I +camlp4 -c ext_repeat.ml ocamlc -c main.ml ocamlc ext_repeat.cmo repeat.cmo main.cmo -linkall -a -o pa_combine.cmo camlp4o ./pa_combine.cmo pr_o.cmo ex.ml The example that I'm using is (ex.ml): -------------- let main () = let i = ref 0 in repeat print_int !i; incr i until !i = 10; print_newline () let _ = main () ------------ however this arrangement doesn't work: camlp4o ./pa_combine.cmo pr_o.cmo ex.ml File "", line 0, characters 0-1: Parse error: [reexpr] expected after 'repeat' (in [expr]) Uncaught exception: Stream.Error("[reexpr] expected after 'repeat' (in [expr])") Is there a way of achieving this kind of modularity with camlp4 ? thanks ! p ps: this is not a re-play of an other thread a while ago... http://caml.inria.fr/pub/ml-archives/caml-list/2006/07/c58bd2a0270a539cccc5a1f7008f8b5c.en.html -- ++ Blog: http://blog.rsise.anu.edu.au/?q=pietro ++ ++ "All great truths begin as blasphemies." -George Bernard Shaw ++ Please avoid sending me Word or PowerPoint attachments. See http://www.fsf.org/philosophy/no-word-attachments.html