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 81838BC48 for ; Sat, 9 Apr 2005 13:55:38 +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 j39Btcg5023666 for ; Sat, 9 Apr 2005 13:55:38 +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 NAA04260 for ; Sat, 9 Apr 2005 13:55:37 +0200 (MET DST) Received: from kraid.nerim.net (smtp-106-saturday.nerim.net [62.4.16.106]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j39BtbG9023663 for ; Sat, 9 Apr 2005 13:55:37 +0200 Received: from localhost (karryall.dnsalias.org [62.4.18.180]) by kraid.nerim.net (Postfix) with ESMTP id 41D994210A; Sat, 9 Apr 2005 13:55:36 +0200 (CEST) Date: Sat, 09 Apr 2005 13:55:36 +0200 (CEST) Message-Id: <20050409.135536.74751436.oandrieu@nerim.net> To: Sebastien.Hinderer@ens-lyon.org Cc: caml-list@inria.fr Subject: Re: [Caml-list] Syntactic inclusion of a.ml in b.ml ? From: Olivier Andrieu In-Reply-To: <20050408174142.GA1804@galois> References: <20050408174142.GA1804@galois> X-Mailer: Mew version 4.1 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sat_Apr__9_13_55_36_2005_142)--" Content-Transfer-Encoding: 8bit X-Miltered: at nez-perce with ID 4257C2BA.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4257C2B9.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 andrieu:01 andrieu:01 ijm:01 gcc:01 ocamlc:01 iirc:01 ocaml:01 syntax:01 parsing:01 cmo:01 pcaml:01 pcaml:01 ocamlc:01 -pp:01 X-Attachments: name="pa_inc.ml" 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: ----Next_Part(Sat_Apr__9_13_55_36_2005_142)-- Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit > Sébastien Hinderer [Fri, 8 Apr 2005]: > Dear all, > > (How) is it possible to include syntactically a file a.ml in a file > b.ml ? > > One method that seems to w)rk is to rename b.ml to b.ml.c, > and then have in b.ml.c a line saying > #include "a.ml" > And with this, gcc -E b.ml.c > b.ml > produces a file that ocamlc can apparently handle. > > But is this considered a good solution, not really : IIRC ocaml doesn't follow the same syntactic conventions as C and the C preprocessor could report errors on valid caml code > or is some better solution available ? you could use camlp4 : the attached syntax extension does this. (Mind that it works only for parsing, the printer apparently gets confused). -- Olivier ----Next_Part(Sat_Apr__9_13_55_36_2005_142)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="pa_inc.ml" #load "pa_extend.cmo";; let include_file file = let ic = open_in file in let (implem, _) = !Pcaml.parse_implem (Stream.of_channel ic) in close_in ic ; (implem, true) EXTEND GLOBAL: Pcaml.implem ; Pcaml.implem: [ [ "INCLUDE" ; file = STRING ; ";;" -> include_file file ] ]; END (* Local Variables: *) (* compile-command: "ocamlc -pp camlp4o -I +camlp4 -c pa_inc.ml" *) (* End: *) ----Next_Part(Sat_Apr__9_13_55_36_2005_142)----