Browse thread
[Caml-list] Printing text with holes
-
Martin Jambon
- Christian Lindig
- Benjamin Geer
- Brian Hurt
- Karl Zilles
- Pierre Weis
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Pierre Weis <pierre.weis@i...> |
| Subject: | Re: [Caml-list] Printing text with holes |
Hello, > I am curious to know what people use to print long text written in a > natural language, and containing many holes, like dynamically generated > web pages. [...] > Does anyone need this kind of approach? > Any better ideas? > > I put my implementation here (it is quite ugly, I still ignore everything > about Camlp4): > http://martin.jambon.free.fr/bazar/printfer.tar.gz Many people use the same approach with dollars. In the 3.07 release of Objective Caml there is some support to easily obtain such a feature: in the interface of the module Buffer, we find val add_substitute : t -> (string -> string) -> string -> unit (** [add_substitute b f s] appends the string pattern [s] at the end of the buffer [b] with substitution. The substitution process looks for variables into the pattern and substitutes each variable name by its value, as obtained by applying the mapping [f] to the variable name. Inside the string pattern, a variable name immediately follows a non-escaped [$] character and is one of the following: - a non empty sequence of alphanumeric or [_] characters, - an arbitrary sequence of characters enclosed by a pair of matching parentheses or curly brackets. An escaped [$] character is a [$] that immediately follows a backslash character; it then stands for a plain [$]. Raise [Not_found] if the closing character of a parenthesized variable cannot be found. *) This may be used to create strings with $identifiers to expand in them. Hope this helps, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners