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 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 5B184BC6B for ; Tue, 6 Nov 2007 19:14:45 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CABU+MEfAXQInh2dsb2JhbACBW40jAQgKKQ X-IronPort-AV: E=Sophos;i="4.21,379,1188770400"; d="scan'208";a="19004472" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 06 Nov 2007 19:14:45 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id lA6IEi1m025014 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 6 Nov 2007 19:14:44 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAPM9MEeCulhph2dsb2JhbACBW40jAQgKKQ X-IronPort-AV: E=Sophos;i="4.21,379,1188770400"; d="scan'208";a="4117780" Received: from fiton.bononia.it ([130.186.88.105]) by mail1-smtp-roc.national.inria.fr with ESMTP; 06 Nov 2007 19:14:44 +0100 Received: from aquarium.takhisis.invalid (fiton.bononia.it [130.186.88.105]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Stefano Zacchiroli", Issuer "sockmel.bononia.it" (verified OK)) by fiton.bononia.it (Postfix) with ESMTP id 083FD38067 for ; Tue, 6 Nov 2007 19:14:25 +0100 (CET) Received: by aquarium.takhisis.invalid (Postfix, from userid 1000) id 4752B1240F6; Tue, 6 Nov 2007 19:14:31 +0100 (CET) Date: Tue, 6 Nov 2007 19:14:31 +0100 From: Stefano Zacchiroli To: Inria Ocaml Mailing List Subject: [camlp4] how to parse/pretty print OCaml source files Message-ID: <20071106181431.GA19764@takhisis.invalid> Mail-Followup-To: Inria Ocaml Mailing List MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) X-Miltered: at concorde with ID 4730AF14.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; zacchiroli:01 zack:01 camlp:01 ocaml:01 ocaml:01 patching:01 syntax:01 camlp:01 wiki:01 wiki:01 pcaml:01 syntax:01 pcaml:01 parsetree:01 toplevel:01 I need to write a simple wrapper around the OCaml top-level. Besides executing top-level phrases as usual, the wrapper should "patch" the pretty-printing of both input phrases and of top-level output. The kind of patching I would need ranges from substituting ascii arts like "->" for suitable unicode symbols to reworking abstract syntax trees of OCaml values. I would have an idea of where to start with camlp5, but not the faintest with (the new) camlp4. The stuff currently on the wiki does not help. So here they go some questions (I'll be happy to write the corresponding articles in the camlp4 wiki ... assuming I'll manage to find the needed info here!) - what's the corresponding camlp4 idiom for the old "Pcaml.parse_implem" (which used to parse str_items starting from a "char Stream.t")? [ Note that I need to parse the revised syntax, but I doubt this will make a sensible difference. ] - what's the camlp4 idiom for the old "Pcaml.print_implem" (which used to print str_items on a given formatter) [ Same remark as above for the revised syntax. ] - what's the camlp4 idiom for "Ast2pt.phrase" (which used to convert str_items to "Parsetree.toplevel_phrase", the type required by the Toploop module for executing phrases), assuming it is still needed of course ... - how can I install with camlp4 a custom printer for OCaml ASTs so that Toploop.execute_phrase uses it to print on the given formatter? Note that I would also be fine in using camlp5 for the task, but AFAIU the code, overriding tiny bits of the default pretty printers for OCaml ASTs is easier with the new camlp4 since it has OO printers. This way I can override methods in derived classes and be done with that. Many thanks in advance, Cheers. -- Stefano Zacchiroli -*- PhD in Computer Science ............... now what? zack@{cs.unibo.it,debian.org,bononia.it} -%- http://www.bononia.it/zack/ (15:56:48) Zack: e la demo dema ? /\ All one has to do is hit the (15:57:15) Bac: no, la demo scema \/ right keys at the right time