On 10/05/2009 06:49 PM, Roger Pack wrote:
>> I tried to cook something up in the past.  You can find it when
>> searching the archives for subject "Alternate Regular Expressions?".
>> HTH
> 
> Very interesting thread.  Did anything come of it? (or florian gross' 
> Regexp::English looks nice [2]-- Florian?)

Yes, one of my postings had a file attached which contained an 
implementation.  I believe Ari also created a project on rubyforge.  We 
certainly did some more polishing of the code but unfortunately I don't 
have the latest version handy.

Actually it's available as gem but it's definitive not the latest 
version that I wrote because it does not contain the optimization for 
multiple fixed strings in an alternative.  I have to see whether I find 
that version somewhere. :-)

> I like this syntax (this example matches things like "-2.718 + 3.14i"):
> 
> PAT.float['re'] + REP0.whitespace  + ALT("+", "-")['op'] + 
> REPO.whitespace + PAT.float['im'] + 'i' [1]
> 
> I'm not sure how to do nested matches or optionals or what not however.
> 
> I suppose that's the equivalent of (in 1.9)
> float =  /[-+]?\d+\.\d+/
> whitespace = /\s+/
> 
> %r{(?<re>#{float})#{whitespace}(?<op>[+-])#{whitespace}(?<im>#{float})i}

Personally I do not like the approach with string interpolation.  I'd 
rather extend the approach of TextualRegexp to include human readable 
variants of these meta sequences via method calls.

> But the kicker is still how to remember that \s is white space, not \w. 
> And we've been forced to do some tip toeing around the complexities of 
> regex in order to make it readable.

Actually, once you have got used to them and take a bit of care they are 
pretty readable.  For example /x goes a long way in making complex 
expressions readable by letting you insert whitespace and comments.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/