Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
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	[thread overview]
Message-ID: <99071819171100.17695@schneemann> (raw)

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                     
----------------------------------------------------------------------------




                 reply	other threads:[~1999-07-21  1:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=99071819171100.17695@schneemann \
    --to=gerd.stolpmann@darmstadt.netsurf.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox