Bug 10824 – Unsupported regexp(?>) error during run time
Status
RESOLVED
Resolution
INVALID
Severity
blocker
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2013-08-15T11:26:00Z
Last change time
2013-08-15T11:41:33Z
Assigned to
dmitry.olsh
Creator
maliyatbaz
Comments
Comment #0 by maliyatbaz — 2013-08-15T11:26:08Z
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]
Comment #1 by dmitry.olsh — 2013-08-15T11:41:33Z
(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]