This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] ada: Accept escaped '(' in a regular expression '()' group
- From: Arnaud Charlet <charlet at adacore dot com>
- To: Samuel Tardieu <sam at rfc1149 dot net>
- Cc: gcc-patches at gcc dot gnu dot org, Emmanuel Briot <briot at adacore dot com>
- Date: Fri, 25 Jul 2008 11:45:49 +0200
- Subject: Re: [PATCH] ada: Accept escaped '(' in a regular expression '()' group
- References: <20080723212247.21C458103@dawn.rfc1149.net>
Here is Emmanuel's review of your patch:
> Without this patch, GNAT rejects the following regular expression
>
> (.\()
I thought initially I could not reproduce the issue, but I was testing
with GNAT.Regpat, which accepts the regexp correctly.
There is indeed a bug in GNAT.Regexp, and your fix is good.
However, it seems a bit inefficient because it requires an array the
size of the string, which I think is unnecessary.
We only need to check whether the last opening parenthesis was the
previous character. Nested parenthesis are automatically handled (if
the one inside is not empty, then the outer one cannot be empty either)
I propose the following patch instead:
--- /home/briot/svn/trunk/gnat/s-regexp.adb 2008-06-27
15:36:45.000000000 +0200 +++ ./s-regexp.adb 2008-07-25
11:38:24.000000000 +0200 @@ -32,7 +32,6 @@
------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
--- with Ada.Exceptions;
with System.Case_Util;
@@ -205,6 +204,7 @@
J : Integer := S'First;
Parenthesis_Level : Integer := 0;
Curly_Level : Integer := 0;
+ Last_Open : Integer := S'First - 1;
-- Start of processing for Create_Mapping
@@ -212,6 +212,7 @@
while J <= S'Last loop
case S (J) is
when Open_Bracket =>
+ Last_Open := J;
J := J + 1;
if S (J) = '^' then
@@ -296,7 +297,7 @@
& "expression", J);
end if;
- if S (J - 1) = Open_Paren then
+ if J = Last_Open + 1 then
Raise_Exception
("Empty parenthesis not allowed in regular "
& "expression", J);