compile-time regex redux

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Wed Feb 7 16:24:24 PST 2007


Robby wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> Walter Bright wrote:
> [snipped]
>>> The last time I introduced core regular expressions into D, it was 
>>> soundly rejected by the community and was withdrawn, and for good 
>>> reasons.
>>>
>>> But I think we now have good reasons to revisit this, at least for 
>>> compile time use only. For example:
>>>
>>>     ("aa|b" ~~ "ababb") would evaluate to "ab"
>>>
>>> I expect one would generally only see this kind of thing inside 
>>> templates, not user code.
>>
>> The more traditional way is to mention the string first and pattern 
>> second, so:
>>
>> ("ababb" ~~ "aa|b") // match this guy against this pattern
>>
>> And I think it returns "b" - juxtaposition has a higher priority than 
>> "|", so your pattern is "either two a's or one b". :o)
>>
>> One program I highly recommend for playing with regexes is The Regex 
>> Coach: http://weitz.de/regex-coach/.
>>
>>
>> Andrei
> 
> I wasn't here during the first round of regexes so bare with me. Though 
> I can assume that with D's growing visibility the past few months, I'm 
> probably not the only one. Having used Ruby for years I'm quite! fond of 
> them, some general questions.
> 
> What version of regex would be the target? There's a few variations out 
> there.

Ionno.

> Probably a couple of green questions, what is the benefit of having a 
> compile time regex implementation over a "really fast" implementation? 
> Or having the expression compiled and the string allowed runtime?

It's not about speed. Compile-time regexes will be most useful for 
parsing and subsequently generating code. Of course, it's great to 
support the same regex syntax and power for both realms.

> Assuming ~~ will be the syntax used?
> 
> Sidebar chuckle :
> http://dev.perl.org/perl6/doc/design/syn/S05.html
> Um, wow. They've really turned 5's implementation on its head.. could be 
> interesting to watch the reaction from that.. could be louder than the 
> vb guys when vb.net was first released..

Interesting how a thorough cleanup is more important than keeping 
everybody happy. :o)


Andrei



More information about the Digitalmars-d mailing list