Thread overview
[Issue 10824] New: Unsupported regexp(?>) error during run time
Aug 15, 2013
milvakili
Aug 15, 2013
Dmitry Olshansky
August 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10824

           Summary: Unsupported regexp(?>) error during run time
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: maliyatbaz@gmail.com


--- Comment #0 from milvakili <maliyatbaz@gmail.com> 2013-08-15 11:26:08 PDT ---
void main(string argv[]) {
auto myRegex = regex(`(?>test)`, "i");
}

Compiles but throws the following run time error.  I think this should be handled during compile time.

std.regex.RegexException@/opt/compilers/dmd2/include/std/regex.d(1947):  ':',
'=', '<', 'P' or '!' expected after '(?'
Pattern with error: `(?>` <--HERE-- `test)`
Pattern with error: `(?>` <--HERE-- `test)`
----------------
/home/d677/f315(ref @trusted std.regex.Parser!(immutable(char)[]).Parser
std.regex.Parser!(immutable(char)[]).Parser.__ctor!(const(char)[]).__ctor(immutable(char)[],
const(char)[])+0x98) [0x469978]
/home/d677/f315(@safe std.regex.Regex!(char).Regex
std.regex.regexImpl!(immutable(char)[]).regexImpl(immutable(char)[],
const(char)[])+0x5a) [0x453bca]
/home/d677/f315(std.regex.Regex!(char).Regex
std.functional.memoize!(_D3std5regex18__T9regexImplTAyaZ9regexImplFNfAyaAxaZS3std5regex12__T5RegexTaZ5Regex,
8).memoize(immutable(char)[], const(char)[])+0xe5) [0x470a55]
/home/d677/f315(@trusted std.regex.Regex!(char).Regex
std.regex.regex!(immutable(char)[]).regex(immutable(char)[],
const(char)[])+0x41) [0x453b59]
/home/d677/f315(_Dmain+0x39) [0x4537f9]
/home/d677/f315(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C)
int function(char[][])*).void runMain()+0x18) [0x47bb4c]
/home/d677/f315(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C)
int function(char[][])*).void tryExec(scope void delegate())+0x2a) [0x47b67e]
/home/d677/f315(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C)
int function(char[][])*).void runAll()+0x40) [0x47bb9c]
/home/d677/f315(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C)
int function(char[][])*).void tryExec(scope void delegate())+0x2a) [0x47b67e]
/home/d677/f315(_d_run_main+0x1ae) [0x47b63a]
/home/d677/f315(main+0x17) [0x47b487]
/usr/lib/libc.so.6(__libc_start_main+0xf5) [0x40967a15]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10824


Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@erdani.com
         AssignedTo|nobody@puremagic.com        |dmitry.olsh@gmail.com
           Severity|normal                      |blocker


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10824


Dmitry Olshansky <dmitry.olsh@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |INVALID


--- Comment #1 from Dmitry Olshansky <dmitry.olsh@gmail.com> 2013-08-15 11:41:33 PDT ---
(In reply to comment #0)
> void main(string argv[]) {
> auto myRegex = regex(`(?>test)`, "i");
> }
> 
> Compiles but throws the following run time error.  I think this should be handled during compile time.

It can't as auto myRegex is a run-time varaible and the expression on the right may as well depend on external variables. See e.g.

auto myRegex = regex(argv[1], "i");

How would that be handled at compile time?

But you can have your checking (and parsing btw) done at C-T using static:
static myRegex = regex(`(?>test)`, "i");

In the above myRegex will be precompiled at CTFE. No spedcial native code generated unlike ctRegex, but no parsing at runtime. If need be you can create static arrays of regex patterns at CTFE and later on assign them to local auto variables.

So I'm marking this as resolved-invalid as there is nothing that can be done to make original do CTFE (at the language level), and there is an easy solution that is explicit and works.

> 
> std.regex.RegexException@/opt/compilers/dmd2/include/std/regex.d(1947):  ':',
> '=', '<', 'P' or '!' expected after '(?'
> Pattern with error: `(?>` <--HERE-- `test)`
> Pattern with error: `(?>` <--HERE-- `test)`
> ----------------
> /home/d677/f315(ref @trusted std.regex.Parser!(immutable(char)[]).Parser
> std.regex.Parser!(immutable(char)[]).Parser.__ctor!(const(char)[]).__ctor(immutable(char)[],
> const(char)[])+0x98) [0x469978]
> /home/d677/f315(@safe std.regex.Regex!(char).Regex
> std.regex.regexImpl!(immutable(char)[]).regexImpl(immutable(char)[],
> const(char)[])+0x5a) [0x453bca]
> /home/d677/f315(std.regex.Regex!(char).Regex
> std.functional.memoize!(_D3std5regex18__T9regexImplTAyaZ9regexImplFNfAyaAxaZS3std5regex12__T5RegexTaZ5Regex,
> 8).memoize(immutable(char)[], const(char)[])+0xe5) [0x470a55]
> /home/d677/f315(@trusted std.regex.Regex!(char).Regex
> std.regex.regex!(immutable(char)[]).regex(immutable(char)[],
> const(char)[])+0x41) [0x453b59]
> /home/d677/f315(_Dmain+0x39) [0x4537f9]
> /home/d677/f315(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C)
> int function(char[][])*).void runMain()+0x18) [0x47bb4c]
> /home/d677/f315(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C)
> int function(char[][])*).void tryExec(scope void delegate())+0x2a) [0x47b67e]
> /home/d677/f315(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C)
> int function(char[][])*).void runAll()+0x40) [0x47bb9c]
> /home/d677/f315(extern (C) int rt.dmain2._d_run_main(int, char**, extern (C)
> int function(char[][])*).void tryExec(scope void delegate())+0x2a) [0x47b67e]
> /home/d677/f315(_d_run_main+0x1ae) [0x47b63a]
> /home/d677/f315(main+0x17) [0x47b487]
> /usr/lib/libc.so.6(__libc_start_main+0xf5) [0x40967a15]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------