Re: String#to_rx ?



Jeff Wood wrote:

> I do agree that I should have reviewed the document before posting a
> response. I have done that, and still hold to what I've stated.
>
> The Perl syntax he proposed is a hideous mess of line noise ( no
> surprises).

So you think /(?:abc)/ is easier to read than /[abc]/? How about
/\w+\s*=\s*\w+/ versus /<word> = <word>/w (or /<word><ws>=<ws><word>/
without 'w' modifier and assuming word = /\w+/)?

> I don't believe that the suggested functionality can be added without
> slowing regular expression matching.

What functionality are you talking about? The obvious one that slows
down matching is the one that executes arbitrary Perl (Ruby) statments,
but you're certainly not forced to use that functionality if you don't
want to, which brings us to...

> But there IS one idea in the document I like and would require NO
> changes to regexp syntax.
>
> # define a normal regex with 1 group
> a = /(\d+)/
>
> # add a rule for group 1s matching
> a.rules << Rexexp::Rule.new( :group, 1 ) { |val| val > 20 }
>
> # now play.
> b = "200 19 14 21 1"
> b.scan a
> #=>[ "200","21" ]
>
> ... at least that's how I'd do it ... Beyond that, I still feel
> trying to get anything more than "ideas" for features from Perl is NOT
> a good path for ruby.

How is that easier to understand than

b = "200 19 14 21 1"
b.scan /(\d+){ |val| val > 2 }/
# => ["200", "21"]

? With this syntax, it's pretty obvious what's going on, at least I
think so. "Match a sequence of one or more digits and call the given
block to see if we should actually accept it as a valid match."

Furthermore, everything could be added _without_ changing the regex
syntax, but that's not the point. The point is to make the regex syntax
as expressive as possible, just like Ruby's syntax is as expressive as
possible (or at least tries to be).

> Anyways, I do see value in what you brought to the table ... but maybe
> next time explain the feature for it's merits not "hey look what perl
> is doing!" ...

I didn't even mention Perl in my original posting. I mentioned an
article about a new regular expression syntax, which happened to be for
Perl 6, but I didn't say "Hey, look what almighty Larry Wall has said we
must do."

nikolai

--
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


.



Relevant Pages

  • Re: PyWart: Python regular expression syntax is not intuitive.
    ... "This module provides regular expression matching operations *similar ... the syntax, so the re module does too. ... Perl style regexes are not Pythonic. ... pass your flags as an argument to the ...
    (comp.lang.python)
  • Re: regular expression for perl, tcl, sed, grep, awk
    ... > I wonder is the regular expression the same for perl, tcl, sed, grep ... > and awk except for the syntax? ... which sorts of RE are supported by your sed, grep and awk. ...
    (comp.lang.perl.misc)
  • Re: String#to_rx ?
    ... No further response. ... >> slowing regular expression matching. ... > down matching is the one that executes arbitrary Perl statments, ... >> changes to regexp syntax. ...
    (comp.lang.ruby)
  • grep using regular expression
    ... syntax. ... I have a log file whose contents are similar to ... I have some general idea about regular expression, ... But i am not clear how it can be used for the following case with perl ...
    (comp.lang.perl.misc)
  • Re: date modified if statement
    ... > I'm rather new to Perl and its syntax, and I did try multiple searches ... > before posting this, but I am using Perl to create a Macro that will ... What would the syntax be for the if statement ...
    (comp.lang.perl.misc)