From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id DAA22404 for caml-redistribution; Wed, 21 Jul 1999 03:08:48 +0200 (MET DST) 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 UAA04430 for ; Sun, 18 Jul 1999 20:00:52 +0200 (MET DST) Received: from beach.frankfurt.netsurf.de ([194.64.181.2]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id UAA10080 for ; Sun, 18 Jul 1999 20:00:44 +0200 (MET DST) From: Gerd.Stolpmann@darmstadt.netsurf.de Received: from schneemann.darmstadt.netsurf.de (board-79.darmstadt.netsurf.de [194.163.86.207]) by beach.frankfurt.netsurf.de (8.8.5/8.8.5) with ESMTP id UAA15562 for ; Sun, 18 Jul 1999 20:00:44 +0200 (MET DST) Received: from localhost (localhost [[UNIX: localhost]]) by schneemann.darmstadt.netsurf.de (8.8.8/8.8.8) id TAA22673 for caml-list@inria.fr; Sun, 18 Jul 1999 19:20:11 +0200 Reply-To: Gerd.Stolpmann@darmstadt.netsurf.de Organization: privat To: caml-list@inria.fr Subject: New software: xstrp4 - '$' expansions for camlp4 Date: Sun, 18 Jul 1999 19:13:03 +0200 X-Mailer: KMail [version 1.0.17] Content-Type: text/plain MIME-Version: 1.0 Message-Id: <99071819171100.17695@schneemann> Content-Transfer-Encoding: 8bit Sender: weis Hi, here is my first camlp4 extension; it implements the '$' expansion known from shells. Below is a simple example. You can download the package xstrp4 from the usual place: http://people.darmstadt.netsurf.de/Gerd.Stolpmann/ocaml/ This package has an entry in the O'Caml link database; updates are announced here: http://www.npc.de/ocaml/linkdb/ And here the example: (**********************************************************************) (* interpolate *) (**********************************************************************) (* interpolate "string": * In the string literal brace expansion is performed. The following * notations are allowed: * $name expands to the value of the string variable 'name' * $Module.name expands to the value of the string variable 'name' * of 'Module' * ${name} same as $name * ${Module.name} same as $Module.name * ${name,%format} expands to the value of the variable 'name' which * has been converted to a string using "%format". * The format string may be anything allowed in printf. * ${Module.name,%format} works,too * \$ A dollar character * \ Expands to the empty string * All backslash sequences of normal string constants are allowed, too. * * NOTE: For non-string variables a format specification is required; * otherwise type checking is impossible. *) let s = "The number" in let f = 3.14 in let i = 42 in print_string interpolate "$s ${f,%f} is not ${i,%d}\n";; (**********************************************************************) (* interpolate file *) (**********************************************************************) (* interpolate file "filename": * expands to the contents of the file; brace expansion is performed * (see above). * If "filename" is written without "/", it is always searched in the * same directory as the source file being compiled. Otherwise "filename" * is interpreted as relative or absolute path name. * * IMPORTANT NOTE: Of course, the file is only read during compile time. *) let s = "The number" in let f = 3.14 in let i = 42 in print_string interpolate file "sample.file";; (**********************************************************************) (* <:here< quotations>> *) (**********************************************************************) (* It is also possible to use the 'here' quotation which does brace * expansion on its argument. This is sometimes easier to write because * the double quotes need no escaping. Of course, $ and \ characters * must still be escaped. * Only \$, \, \>, and \\ are allowed as backslash sequences. *) let s = "The number" in let f = 3.14 in let i = 42 in print_string <:here<\ The interpolation example was: print_string interpolate "\$s \${f,%f} is not \${i,%d}\n";; -- where s was replaced by "$s", f by "${f,%f}", and i by "${i,%d}". >> -- ---------------------------------------------------------------------------- Gerd Stolpmann Telefon: +49 6151 997705 (privat) Viktoriastr. 100 64293 Darmstadt EMail: Gerd.Stolpmann@darmstadt.netsurf.de (privat) Germany ----------------------------------------------------------------------------