* [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
* Re: [Caml-list] scanf question
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
0 siblings, 1 reply; 4+ messages in thread
From: Gabriel Scherer @ 2015-02-21 9:55 UTC (permalink / raw)
To: Milan Stanojević; +Cc: Caml List
[-- Attachment #1: Type: text/plain, Size: 1728 bytes --]
This seems to be a regression caused by the reimplementation of format
strings in 4.02; some "stop after this character" indications are
supported, but some other fail (when they correspond to valid Format
specifications). Would you mind opening a but report (
http://caml.inria.fr/mantis/ )?
On Fri, Feb 20, 2015 at 8:28 PM, Milan Stanojević <milanst@gmail.com> wrote:
> 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)
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
[-- Attachment #2: Type: text/html, Size: 2551 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] scanf question
2015-02-21 9:55 ` Gabriel Scherer
@ 2015-02-21 20:08 ` Benoit Vaugon
2015-02-23 19:08 ` Milan Stanojević
0 siblings, 1 reply; 4+ messages in thread
From: Benoit Vaugon @ 2015-02-21 20:08 UTC (permalink / raw)
To: caml-list
[-- Attachment #1.1: Type: text/plain, Size: 2272 bytes --]
Oups, I confirm it is a bug appearing when we have separated
formatting_gen to formatting_lit in the implementation of formats to
handle Format constructions like "@{<%s>" and "@[<hov %d>" that collides
with scanf constructions like "%s@{" and "%s@[". I attach a patch (+ 6
lines) that fix the problem, if somebody have time to integrate it...
Sorry.
Benoît.
Le 21/02/2015 10:55, Gabriel Scherer a écrit :
> This seems to be a regression caused by the reimplementation of format
> strings in 4.02; some "stop after this character" indications are
> supported, but some other fail (when they correspond to valid Format
> specifications). Would you mind opening a but report (
> http://caml.inria.fr/mantis/ )?
>
> On Fri, Feb 20, 2015 at 8:28 PM, Milan Stanojević <milanst@gmail.com
> <mailto:milanst@gmail.com>> wrote:
>
> 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)
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>
[-- Attachment #1.2: Type: text/html, Size: 4331 bytes --]
[-- Attachment #2: fix-scanf-open-box-tag-patch.diff --]
[-- Type: text/x-patch, Size: 983 bytes --]
diff -Naur old/stdlib/scanf.ml new/stdlib/scanf.ml
--- old/stdlib/scanf.ml 2015-02-21 20:38:02.250636479 +0100
+++ new/stdlib/scanf.ml 2015-02-21 20:53:51.486677851 +0100
@@ -1125,6 +1125,12 @@
let scan width _ ib = scan_string (Some stp) width ib in
let str_rest = String_literal (str, rest) in
pad_prec_scanf ib str_rest readers pad No_precision scan token_string
+ | String (pad, Formatting_gen (Open_tag (Format (fmt', _)), rest)) ->
+ let scan width _ ib = scan_string (Some '{') width ib in
+ pad_prec_scanf ib (concat_fmt fmt' rest) readers pad No_precision scan token_string
+ | String (pad, Formatting_gen (Open_box (Format (fmt', _)), rest)) ->
+ let scan width _ ib = scan_string (Some '[') width ib in
+ pad_prec_scanf ib (concat_fmt fmt' rest) readers pad No_precision scan token_string
| String (pad, rest) ->
let scan width _ ib = scan_string None width ib in
pad_prec_scanf ib rest readers pad No_precision scan token_string
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] scanf question
2015-02-21 20:08 ` Benoit Vaugon
@ 2015-02-23 19:08 ` Milan Stanojević
0 siblings, 0 replies; 4+ messages in thread
From: Milan Stanojević @ 2015-02-23 19:08 UTC (permalink / raw)
To: Benoit Vaugon; +Cc: Caml List
Sorry for the delay, I just created the issue.
http://caml.inria.fr/mantis/view.php?id=6791
Benoit, can you attach your patch there?
On Sat, Feb 21, 2015 at 3:08 PM, Benoit Vaugon <benoit.vaugon@gmail.com> wrote:
> Oups, I confirm it is a bug appearing when we have separated formatting_gen
> to formatting_lit in the implementation of formats to handle Format
> constructions like "@{<%s>" and "@[<hov %d>" that collides with scanf
> constructions like "%s@{" and "%s@[". I attach a patch (+ 6 lines) that fix
> the problem, if somebody have time to integrate it...
>
> Sorry.
> Benoît.
>
>
>
> Le 21/02/2015 10:55, Gabriel Scherer a écrit :
>
> This seems to be a regression caused by the reimplementation of format
> strings in 4.02; some "stop after this character" indications are supported,
> but some other fail (when they correspond to valid Format specifications).
> Would you mind opening a but report ( http://caml.inria.fr/mantis/ )?
>
> On Fri, Feb 20, 2015 at 8:28 PM, Milan Stanojević <milanst@gmail.com> wrote:
>>
>> 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)
>>
>> --
>> Caml-list mailing list. Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>
>
^ 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