caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] scanf question
@ 2015-02-20 19:28 Milan Stanojević
  2015-02-21  9:55 ` Gabriel Scherer
  0 siblings, 1 reply; 4+ messages in thread
From: Milan Stanojević @ 2015-02-20 19:28 UTC (permalink / raw)
  To: Caml List

I want to parse a bash like sequence string, for example
"some-thing{1..20}", and extract the string before first { and then
two numbers inside.

I tried this first
utop # Scanf.sscanf "some-thing{1..3}" "%s{%d..%d}" (fun s n1 n2 -> s,n1,n2);;
Exception: End_of_file.

Then I realized %s is special and needs scanning indication (character @).

So I tried that but I get the same error
utop # Scanf.sscanf "some-thing{1..3}" "%s@{%d..%d}" (fun s n1 n2 -> s,n1,n2);;
Exception: End_of_file.

But if I use some other character as end of string indication then it works.
utop # Scanf.sscanf "some-thingI{1..3}" "%s@I{%d..%d}" (fun s n1 n2 ->
s,n1,n2);;
- : bytes * int * int = ("some-thing", 1, 3)

It seems '{' is somehow special but I can't find anything in the docs
about this.
Can someone explain what is going on here?

Thanks!


p.s. At the end I solved my thing by using a range

utop # Scanf.sscanf "some-thing{1..3}" "%[a-z-]{%d..%d}" (fun s n1 n2
-> s,n1,n2);;
- : bytes * int * int = ("some-thing", 1, 3)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-02-23 19:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-20 19:28 [Caml-list] scanf question Milan Stanojević
2015-02-21  9:55 ` Gabriel Scherer
2015-02-21 20:08   ` Benoit Vaugon
2015-02-23 19:08     ` Milan Stanojević

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).