|
Archives
D Programming
digitalmars.Ddigitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger D.gnu D C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.learn - What's the right way to test if regex.match() hits or not?
I'm trying to use regex.match() for a tokenizer. So I want to compare
my input to a bunch of different regex'es, expecting one to hit and the
rest not to.
Problem is, I can't seem to figure out the "right" way to ask if a hit
occurred. My code is roughly this:
BEGIN CODE
while(input.length > 0)
{
auto r1 = regex("^...something nasty...");
auto r2 = regex("^...something worse...");
auto tmp = match(input, r1);
if(<check r1 here>)
{
ReportTokenType1(tmp.hit())
input = tmp.post();
continue;
}
... and so on ...
}
END CODE
What do I put inside the if()?
P.S. Does anybody know why dmd complains "cannot evaluate at compile
time" when I set those regex objects to "static invariant" so I'm not
rebuilding them with every pass?
Jun 01 2009
On Tue, Jun 2, 2009 at 12:16 AM, Russell Lewis <webmaster villagersonline.com> wrote:P.S. Does anybody know why dmd complains "cannot evaluate at compile time" when I set those regex objects to "static invariant" so I'm not rebuilding them with every pass? Jun 02 2009
Jarrett Billingsley wrote:On Tue, Jun 2, 2009 at 12:16 AM, Russell Lewis <webmaster villagersonline.com> wrote:P.S. Does anybody know why dmd complains "cannot evaluate at compile time" when I set those regex objects to "static invariant" so I'm not rebuilding them with every pass? Jun 02 2009
Jarrett Billingsley wrote:On Tue, Jun 2, 2009 at 11:47 AM, Russell Lewis <webmaster villagersonline.com> wrote:Of course! But then, the code is harder to read. I'll bite the bullet and move it above the loop, but it's ugly. And yeah, I know about CTFI and the issues there...I just thought that regex was designed to allow CTFI. I guess I was wrong? Jun 02 2009
On Tue, Jun 2, 2009 at 11:47 AM, Russell Lewis <webmaster villagersonline.com> wrote:Of course! =A0But then, the code is harder to read. =A0I'll bite the bull= Jun 02 2009
|