[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

gnu-regexp should raise?

Simon Strandgaard

11/26/2003 7:01:00 PM

Why does /[]]/ not raise an exception, when /[]/ does ?


server> ruby -e "p /[]]/.match('a]e').to_a"
-e:1: warning: character class has `]' without escape
["]"]
server> ruby -e "p /[]/.match('a]e').to_a"
-e:1: invalid regular expression; empty character class: /[]/
server>

--
Simon Strandgaard
2 Answers

Nikolai Weibull

11/26/2003 7:35:00 PM

0

* Simon Strandgaard <neoneye@adslhome.dk> [Nov, 26 2003 20:10]:
> Why does /[]]/ not raise an exception, when /[]/ does ?
well, it is standard to allow having ] as the first character in a []
character class definition, as the empty character class is usually
illegal. it is, however, not very obvious and so Ruby complains (with a
warning) if it sees one. I'd say that you should go the Perl6 way and
remove character classes defined in this way from you regex library.
That's what I'm going to do.
nikolai

--
::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}

Simon Strandgaard

11/27/2003 2:45:00 PM

0

On Thu, 27 Nov 2003 04:34:54 +0900, Nikolai Weibull wrote:

> * Simon Strandgaard <neoneye@adslhome.dk> [Nov, 26 2003 20:10]:
>> Why does /[]]/ not raise an exception, when /[]/ does ?
> well, it is standard to allow having ] as the first character in a []
> character class definition, as the empty character class is usually
> illegal. it is, however, not very obvious and so Ruby complains (with a
> warning) if it sees one. I'd say that you should go the Perl6 way and
> remove character classes defined in this way from you regex library.
> That's what I'm going to do.
> nikolai

Good idea, I will do that.


I have just made my first attempt to exercise my regexp-engine
against the rubicon testsuite, status are:
pass=1202, fail=358, pass/total=77.0512820512821

Interesting experience.

--
Simon Strandgaard