www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - using std.regex with (A|B) patterns.

reply "Aquiles" <aquiles.a.lopez gmail.com> writes:
Hello,

While instantiating a floating point regex using 
ctRegex!"\\b[-+]?([0-9]*\\.[0-9]+|[0-9]+)\\B", I got a compiler 
error (see below.) The offending character seems to be '|' and 
when escaped it compiles.

I can reproduce it with a simpler regex:

assert ( match("A", ctRegex!"A|B") );
assert ( match("A", ctRegex!r"A|B") );

Any ideas on how to make (A|B) type regex's using std.regex?

------------------------------------------------------------------
/usr/include/dmd/phobos/std/regex.d(1150): Error: 
assert(this.ir[cast(ulong)orStart].code() == cast(IR)129u) failed
/usr/include/dmd/phobos/std/regex.d(876):        called from 
here: this.parseRegex()
/usr/include/dmd/phobos/std/regex.d(6459):        called from 
here: parser.this(pattern,flags)
/usr/include/dmd/phobos/std/regex.d(6443):        called from 
here: regexImpl(pattern,flags)
/usr/include/dmd/phobos/std/regex.d(6468):        called from 
here: regex("\\b[-+]?([0-9]*\\.[0-9]+|[0-9]+)\\B",[])
Nov 18 2012
parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
11/19/2012 11:55 AM, Aquiles пишет:
 Hello,

 While instantiating a floating point regex using
 ctRegex!"\\b[-+]?([0-9]*\\.[0-9]+|[0-9]+)\\B", I got a compiler error
 (see below.) The offending character seems to be '|' and when escaped it
 compiles.

 I can reproduce it with a simpler regex:

 assert ( match("A", ctRegex!"A|B") );
 assert ( match("A", ctRegex!r"A|B") );

See the bug: http://d.puremagic.com/issues/show_bug.cgi?id=7440 The main cause was a compiler bug and is fixed in the upstream. Now the only piece left is this tiny problem in the standard library: http://d.puremagic.com/issues/show_bug.cgi?id=8349 The root of problem is that ctRegex is not throughly tested at the moment (still takes too much time to compile) and certain changes to the standard library broke it silently. There is a pull to just fix it: https://github.com/D-Programming-Language/phobos/pull/936 And another that reworks the whole std.algorithm.move more properly and fixes it: https://github.com/D-Programming-Language/phobos/pull/923 That should be the up to date status on this. Anyway I'm making sure it works as expected in v2.061 when it's out.
 Any ideas on how to make (A|B) type regex's using std.regex?

For the moment use run-time version that is simply regex not ctRegex. -- Dmitry Olshansky
Nov 19 2012