Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Pattern matching and strings
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alessandro Baretta <alex@b...>
Subject: Re: [Caml-list] Pattern matching and strings (and a mini-bug in Scanf)


Pierre Weis wrote:
> This is not a mini-bug, this is a carefully crafted feature and
> thoroughly considered design decision :(
> 
> "%[]" is not allowed because we need to allow the matching of the
> closing bracket. Hence, if ']' just follows the opening bracket (or
> the ^ character, in case of negative range) it is considered as a
> plain ']' (or ascii code 93) to be matched.
> 
> So "%[]]" means matching ']' (well, more precisely zero or more ']');
> more generally, "%[]range]" means matching ']' or range; "%[^]range]"
> means matching any character different from ']' and not belonging to
> range.

I probably did not consider the problem thoroughly enough. I 
was expecting "%[]]" to match a range of ']' and "%[]" to 
match the empty range of characters (which is a rather 
useless construct anyway, as you point out). Now I realize 
this would render almost impossible the interpretation of a 
such a format as "%[]abcdefg...": you simply never know if 
it is the prefix of a range conversion specifier or a empty 
range conversion specifier followed by a string constant 
specifier.

While the empty range conversion is admittedly useless, a 
full range conversion is a whole different story. Coding it 
as "%[\000-\255]" is possible, but maybe it would useful to 
add a "%z" specifier to mean "read till the end of input".

What do you think?

Alex

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