Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Escaped string in sexplib
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-06-08 (18:52)
From: Hugo Ferreira <hmf@i...>
Subject: Re: [Caml-list] Escaped string in sexplib

Markus Mottl wrote:
> On Tue, Jun 8, 2010 at 11:44, Hugo Ferreira <> wrote:
>> I am trying to us the Sexplib library to process data.
>> However I am having some trouble with strings.
>> Specifically I need to save and restore strings to a file
>> so that the escaping done during saving is "undone"
>> when data is read back in.
>> How can I do this? Appreciate any pointers.
> The I/O and parsing routines in the S-expression library should take
> care of escaped strings just fine.  

My apologies but I did not explain myself correctly. The problem here is
that I am trying to automate the conversion to string of the data
structure read from the s-expressions. I have the following:

let string_of_experiment_data data =
   let data = sexp_of_experiment_data data in
   Sexplib.Sexp.to_string_hum data

The problem here is that the "to_string_hum" escapes certain characters,
but I need to have the strings "not escaped". So my question is: is
their any way I can tell sexplib to output a string but not escape
it? Otherwise I will have to hand encode this stuff 8-(

> Btw., the escaping conventions are
> absolutely identical to the ones used by OCaml.

I am aware of this as it is indicated in your documentation and
the ocaml tutorial site. I also searched for a means to "unescape"
the result from "to_string_hum", which would also work. However
I cannot find a String.unescape. This issue has already been pointed
out. A possible solution would be to use the old.


and I cannot seem to use the equivalent of the new camlp4. The

open Camlp4.PreCast
open Syntax
let eval_string s = Camlp4.Struct.Token.Eval.string ~strict:() s

does not compile (Error: Unbound module Camlp4.PreCast).

Can anyone suggest a solution or correction?

Hugo F.

> Regards,
> Markus