New software: xstrp4 - '$' expansions for camlp4

From: Gerd.Stolpmann@darmstadt.netsurf.de
Date: Sun Jul 18 1999 - 19:13:03 MET DST


From: Gerd.Stolpmann@darmstadt.netsurf.de
To: caml-list@inria.fr
Subject: New software: xstrp4 - '$' expansions for camlp4
Date: Sun, 18 Jul 1999 19:13:03 +0200
Message-Id: <99071819171100.17695@schneemann>

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
 * \<newline> 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 \$, \<newline>, \>, 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                     
----------------------------------------------------------------------------



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:23 MET