-- --
-- S p e c --
-- --
--- Copyright (C) 1997-2002 Ada Core Technologies, Inc. --
+-- Copyright (C) 1997-2006, 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- --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
--- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
--- MA 02111-1307, USA. --
+-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
+-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- language is modeled on context free grammars, with context sensitive
-- extensions that provide full (type 0) computational capabilities.
-with Ada.Finalization; use Ada.Finalization;
with Ada.Strings.Maps; use Ada.Strings.Maps;
with Ada.Text_IO; use Ada.Text_IO;
package GNAT.Spitbol.Patterns is
-pragma Elaborate_Body (Patterns);
+ pragma Elaborate_Body;
-------------------------------
-- Pattern Matching Tutorial --
-- Abort Cancel
-- Rem Rest
- -- where we have clashes with Ada reserved names.
+ -- where we have clashes with Ada reserved names
-- Ada requires the use of 'Access to refer to functions used in the
-- pattern match, and often the use of 'Unrestricted_Access may be
function "&" (L : PChar; R : Pattern) return Pattern;
function "&" (L : Pattern; R : PChar) return Pattern;
- -- Pattern concatenation. Matches L followed by R.
+ -- Pattern concatenation. Matches L followed by R
function "or" (L : Pattern; R : Pattern) return Pattern;
function "or" (L : PString; R : Pattern) return Pattern;
function Any (Str : VString) return Pattern;
function Any (Str : Character) return Pattern;
function Any (Str : Character_Set) return Pattern;
- function Any (Str : access VString) return Pattern;
+ function Any (Str : not null access VString) return Pattern;
function Any (Str : VString_Func) return Pattern;
-- Constructs a pattern that matches a single character that is one of
-- the characters in the given argument. The pattern fails if the current
function Break (Str : VString) return Pattern;
function Break (Str : Character) return Pattern;
function Break (Str : Character_Set) return Pattern;
- function Break (Str : access VString) return Pattern;
+ function Break (Str : not null access VString) return Pattern;
function Break (Str : VString_Func) return Pattern;
-- Constructs a pattern that matches a (possibly null) string which
-- is immediately followed by a character in the given argument. This
function BreakX (Str : VString) return Pattern;
function BreakX (Str : Character) return Pattern;
function BreakX (Str : Character_Set) return Pattern;
- function BreakX (Str : access VString) return Pattern;
+ function BreakX (Str : not null access VString) return Pattern;
function BreakX (Str : VString_Func) return Pattern;
-- Like Break, but the pattern attempts to extend on a failure to find
-- the next occurrence of a character in Str, and only fails when the
-- Constructs a pattern that immediately aborts the entire match
function Fail return Pattern;
- -- Constructs a pattern that always fails.
+ -- Constructs a pattern that always fails
function Fence return Pattern;
-- Constructs a pattern that matches null on the first attempt, and then
-- one attempt is made to match P, without trying alternatives.
function Len (Count : Natural) return Pattern;
- function Len (Count : access Natural) return Pattern;
+ function Len (Count : not null access Natural) return Pattern;
function Len (Count : Natural_Func) return Pattern;
-- Constructs a pattern that matches exactly the given number of
-- characters. The pattern fails if fewer than this number of characters
function NotAny (Str : VString) return Pattern;
function NotAny (Str : Character) return Pattern;
function NotAny (Str : Character_Set) return Pattern;
- function NotAny (Str : access VString) return Pattern;
+ function NotAny (Str : not null access VString) return Pattern;
function NotAny (Str : VString_Func) return Pattern;
-- Constructs a pattern that matches a single character that is not
-- one of the characters in the given argument. The pattern Fails if
function NSpan (Str : VString) return Pattern;
function NSpan (Str : Character) return Pattern;
function NSpan (Str : Character_Set) return Pattern;
- function NSpan (Str : access VString) return Pattern;
+ function NSpan (Str : not null access VString) return Pattern;
function NSpan (Str : VString_Func) return Pattern;
-- Constructs a pattern that matches the longest possible string
-- consisting entirely of characters from the given argument. The
-- string may be empty, so this pattern always succeeds.
function Pos (Count : Natural) return Pattern;
- function Pos (Count : access Natural) return Pattern;
+ function Pos (Count : not null access Natural) return Pattern;
function Pos (Count : Natural_Func) return Pattern;
-- Constructs a pattern that matches the null string if exactly Count
-- characters have already been matched, and otherwise fails.
-- unmatched characters in the pattern.
function Rpos (Count : Natural) return Pattern;
- function Rpos (Count : access Natural) return Pattern;
+ function Rpos (Count : not null access Natural) return Pattern;
function Rpos (Count : Natural_Func) return Pattern;
-- Constructs a pattern that matches the null string if exactly Count
-- characters remain to be matched in the string, and otherwise fails.
function Rtab (Count : Natural) return Pattern;
- function Rtab (Count : access Natural) return Pattern;
+ function Rtab (Count : not null access Natural) return Pattern;
function Rtab (Count : Natural_Func) return Pattern;
-- Constructs a pattern that matches from the current location until
-- exactly Count characters remain to be matched in the string. The
-- pattern fails if fewer than Count characters remain to be matched.
- function Setcur (Var : access Natural) return Pattern;
+ function Setcur (Var : not null access Natural) return Pattern;
-- Constructs a pattern that matches the null string, and assigns the
-- current cursor position in the string. This value is the number of
-- characters matched so far. So it is zero at the start of the match.
function Span (Str : VString) return Pattern;
function Span (Str : Character) return Pattern;
function Span (Str : Character_Set) return Pattern;
- function Span (Str : access VString) return Pattern;
+ function Span (Str : not null access VString) return Pattern;
function Span (Str : VString_Func) return Pattern;
-- Constructs a pattern that matches the longest possible string
-- consisting entirely of characters from the given argument. The
-- infinite alternation of null strings.
function Tab (Count : Natural) return Pattern;
- function Tab (Count : access Natural) return Pattern;
+ function Tab (Count : not null access Natural) return Pattern;
function Tab (Count : Natural_Func) return Pattern;
-- Constructs a pattern that from the current location until Count
-- characters have been matched. The pattern fails if more than Count
function Match
(Subject : VString;
- Pat : Pattern)
- return Boolean;
+ Pat : Pattern) return Boolean;
function Match
(Subject : VString;
- Pat : PString)
- return Boolean;
+ Pat : PString) return Boolean;
function Match
(Subject : String;
- Pat : Pattern)
- return Boolean;
+ Pat : Pattern) return Boolean;
function Match
(Subject : String;
- Pat : PString)
- return Boolean;
+ Pat : PString) return Boolean;
-- Replacement functions. The subject is matched against the pattern.
-- Any immediate or deferred assignments or writes are executed, and
function Match
(Subject : VString_Var;
Pat : Pattern;
- Replace : VString)
- return Boolean;
+ Replace : VString) return Boolean;
function Match
(Subject : VString_Var;
Pat : PString;
- Replace : VString)
- return Boolean;
+ Replace : VString) return Boolean;
function Match
(Subject : VString_Var;
Pat : Pattern;
- Replace : String)
- return Boolean;
+ Replace : String) return Boolean;
function Match
(Subject : VString_Var;
Pat : PString;
- Replace : String)
- return Boolean;
+ Replace : String) return Boolean;
-- Simple match procedures. The subject is matched against the pattern.
-- Any immediate or deferred assignments or writes are executed. No
function Match
(Subject : VString_Var;
Pat : Pattern;
- Result : Match_Result_Var)
- return Boolean;
+ Result : Match_Result_Var) return Boolean;
procedure Match
(Subject : in out VString;
-- except that instead of setting the value of a variable, the matched
-- substring is written to the appropriate file. This can be useful in
-- following the progress of a match without generating the full amount
-
-- of information obtained by setting Debug_Mode to True.
Terminal : constant File_Access := Standard_Error;
Output : constant File_Access := Standard_Output;
- -- Two handy synonyms for use with the above pattern write operations.
+ -- Two handy synonyms for use with the above pattern write operations
-- Finally we have some routines that are useful for determining what
-- patterns are in use, particularly if they are constructed dynamically.
-- Maximum number of stack entries required for matching this
-- pattern. See description of pattern history stack in body.
- P : PE_Ptr := null;
+ P : PE_Ptr := null;
-- Pointer to initial pattern element for pattern
end record;
-- Adjust routine used to copy pattern objects
procedure Finalize (Object : in out Pattern);
- -- Finalization routine used to release storage allocated for a pattern.
+ -- Finalization routine used to release storage allocated for a pattern
type VString_Ptr is access all VString;
type Match_Result is record
- Var : VString_Ptr;
- -- Pointer to subject string. Set to null if match failed.
+ Var : VString_Ptr;
+ -- Pointer to subject string. Set to null if match failed
Start : Natural := 1;
-- Starting index position (1's origin) of matched section of
-- subject string. Only valid if Var is non-null.
- Stop : Natural := 0;
+ Stop : Natural := 0;
-- Ending index position (1's origin) of matched section of
-- subject string. Only valid if Var is non-null.