gcc-patches@gcc.gnu.org
[Top] [All Lists]
Try out TrashMail.net disposable email address service

Re: [PATCH] ada: Accept escaped '(' in a regular expression '()' group

Subject: Re: [PATCH] ada: Accept escaped '(' in a regular expression '()' group
From: Arnaud Charlet
Date: Fri, 25 Jul 2008 11:45:49 +0200
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);

<Prev in Thread] Current Thread [Next in Thread>