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.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 8BB62BC6B for ; Tue, 6 Mar 2007 19:40:44 +0100 (CET) Received: from smtp6-g19.free.fr (smtp6-g19.free.fr [212.27.42.36]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l26IeiAE015843 for ; Tue, 6 Mar 2007 19:40:44 +0100 Received: from [192.168.1.2] (che78-2-82-237-71-191.fbx.proxad.net [82.237.71.191]) by smtp6-g19.free.fr (Postfix) with ESMTP id E194A89FD; Tue, 6 Mar 2007 19:40:43 +0100 (CET) Message-ID: <45EDB5AB.2000601@inria.fr> Date: Tue, 06 Mar 2007 19:40:43 +0100 From: Xavier Leroy User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Bruno De Fraine Cc: caml-list@inria.fr Subject: Re: [Caml-list] Format module for C-style syntax References: <70DC8A37-C742-405E-83E4-2367664717F5@vub.ac.be> In-Reply-To: <70DC8A37-C742-405E-83E4-2367664717F5@vub.ac.be> X-Enigmail-Version: 0.91.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 45EDB5AC.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; c-style:01 syntax:01 c-style:01 syntax:01 decl:01 ppf:01 fprintf:01 ppf:01 iter:01 fprintf:01 caml-list:01 module:03 module:03 let:03 indentation:04 > Has anybody used the Format module for pretty-printing C-style syntax? > After reading the documentation ("Using the Format module"), I cannot > get it to line up the braces in a manner that is convential for such a > syntax. Here is one possible solution: let pretty_decl ppf (Procedure(name, body)) = fprintf ppf "@[procedure %s {" name; List.iter (fun (Call s) -> fprintf ppf "@ %s;" s) body; fprintf ppf "@;<1 -4>}@]";; The two tricks are: 1- using only one box that starts at "procedure", no need to start a new box at the opening brace; 2- the "@;", a.k.a. print_break, with a negative offset that cancels the indentation of the current block; it's a bit of a hack but surprisingly useful. Hope this helps, - Xavier Leroy