Skip to content

Commit

Permalink
Fix regexp for anchored search
Browse files Browse the repository at this point in the history
when the last group does't end the position where match ends.
Like when pattern `(X)_` matches `X_` subject. Last group (1)
matches `X` while whole pattern matches `X_`. Anchored check
was wrong because whole match tags stored in the begining of
tag array, not at the end.
  • Loading branch information
reznikmm committed Feb 3, 2023
1 parent f321338 commit eb08469
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--
-- Copyright (C) 2020-2022, AdaCore
-- Copyright (C) 2020-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0
--
Expand Down Expand Up @@ -342,7 +342,7 @@ package body VSS.Regular_Expressions.Pike_Engines is

if Found and then
(not Options (Anchored_Match) or else
VSS.Strings.Character_Count (Final_Tags (Self.Last_Tag).Index) =
VSS.Strings.Character_Count (Final_Tags (2).Index) =
Subject.After_Last_Character.Character_Index)
then
Result := new VSS.Regular_Expressions.Matches.Match
Expand Down
3 changes: 2 additions & 1 deletion testsuite/regexp/test_regexp-test_v406_014.adb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
--
-- Copyright (C) 2022, AdaCore
-- Copyright (C) 2022-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0
--

with VSS.Regular_Expressions;
pragma Warnings (Off, "is not referenced");
with VSS.Strings.Character_Iterators;

separate (Test_Regexp)
Expand Down
3 changes: 2 additions & 1 deletion testsuite/regexp/test_regexp-test_v406_018.adb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
--
-- Copyright (C) 2022, AdaCore
-- Copyright (C) 2022-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0
--

with VSS.Regular_Expressions;
pragma Warnings (Off, "is not referenced");
with VSS.Strings.Character_Iterators;

separate (Test_Regexp)
Expand Down
33 changes: 11 additions & 22 deletions testsuite/regexp/test_regexp-test_v615_026.adb
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
------------------------------------------------------------------------------
-- M A G I C R U N T I M E --
-- --
-- Copyright (C) 2022, AdaCore --
-- --
-- This library is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 3, or (at your option) any later --
-- version. This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
------------------------------------------------------------------------------
--
-- Copyright (C) 2022-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0
--

with VSS.Regular_Expressions;
with VSS.Strings;
Expand All @@ -33,6 +16,8 @@ procedure Test_V615_026 is
VSS.Regular_Expressions.To_Regular_Expression ("bc");
R2 : constant VSS.Regular_Expressions.Regular_Expression :=
VSS.Regular_Expressions.To_Regular_Expression ("^bc");
R3 : constant VSS.Regular_Expressions.Regular_Expression :=
VSS.Regular_Expressions.To_Regular_Expression ("(b)c");
M : VSS.Regular_Expressions.Regular_Expression_Match;

X : constant VSS.Regular_Expressions.Match_Options :=
Expand All @@ -52,6 +37,10 @@ begin
Test_Support.Assert (M.Has_Match);
M := R2.Match (BC);
Test_Support.Assert (M.Has_Match);
M := R3.Match (BC, X);
Test_Support.Assert (M.Has_Match);
M := R3.Match (ABC, X);
Test_Support.Assert (not M.Has_Match);

if Pos.Forward then -- Skip `a`
M := R2.Match (ABC, Pos);
Expand Down

0 comments on commit eb08469

Please sign in to comment.