summaryrefslogtreecommitdiff
path: root/gcc/ada/s-regpat.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2014-08-01 10:15:59 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2014-08-01 10:15:59 +0000
commitdd4c44af4bc54551f96f01d22b77282848a11388 (patch)
tree2ad58359fd383b19cc1da5d950b502f3eb5a1b82 /gcc/ada/s-regpat.adb
parent8c7ee4acb35d6557d18f07d8377b16ae4cc0b340 (diff)
downloadgcc-dd4c44af4bc54551f96f01d22b77282848a11388.tar.gz
2014-08-01 Ed Schonberg <schonberg@adacore.com>
* sem_ch13.adb (Analyze_Aspect_Specifications, case Aspect_Import): Set Is_Imported flag at once, to simplify subsequent legality checks. Reject the aspect on an object whose declaration has an explicit initial value. * sem_prag.adb (Process_Import_Or_Interface): Use original node to check legality of an initial value for an imported entity. Set Is_Imported flag in case of error to prevent cascaded errors. Do not set the Is_Imported flag if the pragma comes from an aspect, because it is already done when analyzing the aspect. 2014-08-01 Emmanuel Briot <briot@adacore.com> * g-regpat.adb (Parse): Add support for non-capturing parenthesis. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@213447 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/s-regpat.adb')
-rw-r--r--gcc/ada/s-regpat.adb58
1 files changed, 37 insertions, 21 deletions
diff --git a/gcc/ada/s-regpat.adb b/gcc/ada/s-regpat.adb
index d32bb03f06d..842b6e362c2 100644
--- a/gcc/ada/s-regpat.adb
+++ b/gcc/ada/s-regpat.adb
@@ -7,7 +7,7 @@
-- B o d y --
-- --
-- Copyright (C) 1986 by University of Toronto. --
--- Copyright (C) 1999-2013, AdaCore --
+-- Copyright (C) 1999-2014, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -410,10 +410,13 @@ package body System.Regpat is
procedure Parse
(Parenthesized : Boolean;
+ Capturing : Boolean;
Flags : out Expression_Flags;
IP : out Pointer);
-- Parse regular expression, i.e. main body or parenthesized thing
-- Caller must absorb opening parenthesis.
+ -- Capturing should be set to True when we have an open parenthesis
+ -- from which we want the user to extra text.
procedure Parse_Branch
(Flags : out Expression_Flags;
@@ -831,9 +834,10 @@ package body System.Regpat is
-- the branches to what follows makes it hard to avoid.
procedure Parse
- (Parenthesized : Boolean;
- Flags : out Expression_Flags;
- IP : out Pointer)
+ (Parenthesized : Boolean;
+ Capturing : Boolean;
+ Flags : out Expression_Flags;
+ IP : out Pointer)
is
E : String renames Expression;
Br, Br2 : Pointer;
@@ -847,7 +851,7 @@ package body System.Regpat is
-- Make an OPEN node, if parenthesized
- if Parenthesized then
+ if Parenthesized and then Capturing then
if Matcher.Paren_Count > Max_Paren_Count then
Fail ("too many ()");
end if;
@@ -856,7 +860,6 @@ package body System.Regpat is
Matcher.Paren_Count := Matcher.Paren_Count + 1;
IP := Emit_Node (OPEN);
Emit (Character'Val (Par_No));
-
else
IP := 0;
Par_No := 0;
@@ -913,14 +916,19 @@ package body System.Regpat is
-- Make a closing node, and hook it on the end
if Parenthesized then
- Ender := Emit_Node (CLOSE);
- Emit (Character'Val (Par_No));
+ if Capturing then
+ Ender := Emit_Node (CLOSE);
+ Emit (Character'Val (Par_No));
+ Link_Tail (IP, Ender);
+ else
+ -- need to keep looking after the closing parenthesis
+ null;
+ end if;
else
Ender := Emit_Node (EOP);
+ Link_Tail (IP, Ender);
end if;
- Link_Tail (IP, Ender);
-
if Have_Branch and then Emit_Ptr <= PM.Size + 1 then
-- Hook the tails of the branches to the closing node
@@ -945,7 +953,7 @@ package body System.Regpat is
elsif Parse_Pos <= Parse_End then
if E (Parse_Pos) = ')' then
- Fail ("unmatched ()");
+ Fail ("unmatched ')'");
else
Fail ("junk on end"); -- "Can't happen"
end if;
@@ -1003,16 +1011,24 @@ package body System.Regpat is
New_Flags : Expression_Flags;
begin
- Parse (True, New_Flags, IP);
-
- if IP = 0 then
- return;
+ if Parse_Pos <= Parse_End - 1
+ and then Expression (Parse_Pos) = '?'
+ and then Expression (Parse_Pos + 1) = ':'
+ then
+ Parse_Pos := Parse_Pos + 2;
+ -- non-capturing parenthesis
+ Parse (True, False, New_Flags, IP);
+ else
+ -- capturing parenthesis
+ Parse (True, True, New_Flags, IP);
+ Expr_Flags.Has_Width :=
+ Expr_Flags.Has_Width or else New_Flags.Has_Width;
+ Expr_Flags.SP_Start :=
+ Expr_Flags.SP_Start or else New_Flags.SP_Start;
+ if IP = 0 then
+ return;
+ end if;
end if;
-
- Expr_Flags.Has_Width :=
- Expr_Flags.Has_Width or else New_Flags.Has_Width;
- Expr_Flags.SP_Start :=
- Expr_Flags.SP_Start or else New_Flags.SP_Start;
end;
when '|' | ASCII.LF | ')' =>
@@ -1971,7 +1987,7 @@ package body System.Regpat is
-- Start of processing for Compile
begin
- Parse (False, Expr_Flags, Result);
+ Parse (False, False, Expr_Flags, Result);
if Result = 0 then
Fail ("Couldn't compile expression");