* New software: xstrp4 - '$' expansions for camlp4
@ 1999-07-18 17:13 Gerd.Stolpmann
0 siblings, 0 replies; only message in thread
From: Gerd.Stolpmann @ 1999-07-18 17:13 UTC (permalink / raw)
To: caml-list
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
----------------------------------------------------------------------------
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1999-07-21 1:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-18 17:13 New software: xstrp4 - '$' expansions for camlp4 Gerd.Stolpmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox