From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id C2DE2BBAF for ; Tue, 28 Sep 2010 15:13:15 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq0BALuGoUzRVdi2kGdsb2JhbACiFAgVAQEBAQkJDAcRAx+tCIlBgheHDy6IVQEBAwWFPwSES4Vv X-IronPort-AV: E=Sophos;i="4.57,247,1283724000"; d="scan'208";a="71641405" Received: from mail-qy0-f182.google.com ([209.85.216.182]) by mail4-smtp-sop.national.inria.fr with ESMTP; 28 Sep 2010 15:13:15 +0200 Received: by qyk7 with SMTP id 7so6624490qyk.6 for ; Tue, 28 Sep 2010 06:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=GXfV+Bh9sNLuqweNKdazJml7hm8YA2e+UhELhupV1s8=; b=erJ1o/M3F0OKosL6EMBpA+cxGTOksJj1KPfaEzjTjhD0+0P2oQu02AZgF6z3vc2yk+ OzzP3iXxhGHvSfaN3QYvZGzi2Wv3kyU+n/hUXCYCX1D+o+rHjXtij1sZ42vRk0ffNbFX QaL1dUMs0YrNWYK6n+vb44e4yWtLYthh6sVMc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=ls09qXVr55ZN4eYw4N9XLfU6i/ALc6cW5Tsl0F5PL/G5WDSYJdqPp3au6zKcg8NTA4 qr+/NPcj60I27TkLzeX9Q6EMC0+e+kNO/wz54j0nyd5co/IdTYasLspmunw+xk4GMVRh 2suLCTAvBSRDQ87YVLBAxZZEtwSwZm9jgm59Y= MIME-Version: 1.0 Received: by 10.224.60.83 with SMTP id o19mr6072439qah.265.1285679594379; Tue, 28 Sep 2010 06:13:14 -0700 (PDT) Received: by 10.229.224.8 with HTTP; Tue, 28 Sep 2010 06:13:13 -0700 (PDT) Date: Tue, 28 Sep 2010 17:13:13 +0400 Message-ID: Subject: Chain Camlp4 syntax extensions? From: Dmitry Bely To: Caml List Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; camlp:01 syntax:01 syntax:01 ocamlc:01 -pp:01 camlp:01 cmo:01 ocamlc:01 -pp:01 cmo:01 rewriting:01 unacceptable:01 ioxml:01 pcaml:01 val:01 I have two similar syntax extension that generate some functions for each type in the module: EXTEND Gram str_item: [ [ "type"; tdl = LIST1 type_declaration SEP "and" -> ... END; So I use them as usual: ocamlc -c -pp "camlp4o pa_ext1.cmo" file.ml or ocamlc -c -pp "camlp4o pa_ext2.cmo" file.ml Now I need to apply them both to the same source file in sequence (without rewriting the extensions if possible). What is the right way to do that? Of course, If I write ocamlc -c -pp "camlp4o pa_ext1.cmo pa_ext2.cmo" file.ml only pa_ext2 extension is actually applied. Calling camlp4o twice with an intermediate text representation works but is actually unacceptable (the error location info is lost etc.). Any advice? And another question. For camlp5 it was possible to inject some code into the beginning of the generated file (the code is taken from IoXML syntax extension): value first = ref True; Pcaml.parse_implem.val := fun strm -> let (sil, stopped) = Grammar.Entry.parse Pcaml.implem strm in let sil = if first.val then let _ = do { first.val := False } in let _loc = Stdpp.dummy_loc in [(<:str_item< open IoXML >>, _loc) :: sil] else sil in (sil, stopped) ; How to do the same with camlp4? - Dmitry Bely