annotate gcc/ada/libgnat/s-regexp.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . R E G E X P --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1998-2019, AdaCore --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- Simple Regular expression matching
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 -- This package provides a simple implementation of a regular expression
kono
parents:
diff changeset
35 -- pattern matching algorithm, using a subset of the syntax of regular
kono
parents:
diff changeset
36 -- expressions copied from familiar Unix style utilities.
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 -- Note: this package is in the System hierarchy so that it can be directly
kono
parents:
diff changeset
39 -- be used by other predefined packages. User access to this package is via
kono
parents:
diff changeset
40 -- a renaming of this package in GNAT.Regexp (file g-regexp.ads).
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 with Ada.Finalization;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 package System.Regexp is
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 -- The regular expression must first be compiled, using the Compile
kono
parents:
diff changeset
47 -- function, which creates a finite state matching table, allowing
kono
parents:
diff changeset
48 -- very fast matching once the expression has been compiled.
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 -- The following is the form of a regular expression, expressed in Ada
kono
parents:
diff changeset
51 -- reference manual style BNF is as follows
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 -- regexp ::= term
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 -- regexp ::= term | term -- alternation (term or term ...)
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 -- term ::= item
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 -- term ::= item item ... -- concatenation (item then item)
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 -- item ::= elmt -- match elmt
kono
parents:
diff changeset
62 -- item ::= elmt * -- zero or more elmt's
kono
parents:
diff changeset
63 -- item ::= elmt + -- one or more elmt's
kono
parents:
diff changeset
64 -- item ::= elmt ? -- matches elmt or nothing
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 -- elmt ::= nchr -- matches given character
kono
parents:
diff changeset
67 -- elmt ::= [nchr nchr ...] -- matches any character listed
kono
parents:
diff changeset
68 -- elmt ::= [^ nchr nchr ...] -- matches any character not listed
kono
parents:
diff changeset
69 -- elmt ::= [char - char] -- matches chars in given range
kono
parents:
diff changeset
70 -- elmt ::= . -- matches any single character
kono
parents:
diff changeset
71 -- elmt ::= ( regexp ) -- parens used for grouping
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 -- char ::= any character, including special characters
kono
parents:
diff changeset
74 -- nchr ::= any character except \()[].*+?^ or \char to match char
kono
parents:
diff changeset
75 -- ... is used to indication repetition (one or more terms)
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 -- See also regexp(1) man page on Unix systems for further details
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 -- A second kind of regular expressions is provided. This one is more
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
80 -- like the wildcard patterns used in file names by the Unix shell (or
111
kono
parents:
diff changeset
81 -- DOS prompt) command lines. The grammar is the following:
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 -- regexp ::= term
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 -- term ::= elmt
kono
parents:
diff changeset
86 -- term ::= elmt elmt ... -- concatenation (elmt then elmt)
kono
parents:
diff changeset
87 -- term ::= {elmt, elmt, ...} -- alternation (matches any of elmt)
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 -- elmt ::= * -- any string of 0 or more characters
kono
parents:
diff changeset
90 -- elmt ::= ? -- matches any character
kono
parents:
diff changeset
91 -- elmt ::= char
kono
parents:
diff changeset
92 -- elmt ::= [^ char char ...] -- matches any character not listed
kono
parents:
diff changeset
93 -- elmt ::= [char char ...] -- matches any character listed
kono
parents:
diff changeset
94 -- elmt ::= [char - char] -- matches any character in given range
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 -- \char is also supported by this grammar.
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 -- Important note : This package was mainly intended to match regular
kono
parents:
diff changeset
99 -- expressions against file names. The whole string has to match the
kono
parents:
diff changeset
100 -- regular expression. If only a substring matches, then the function
kono
parents:
diff changeset
101 -- Match will return False.
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 type Regexp is private;
kono
parents:
diff changeset
104 -- Private type used to represent a regular expression
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 Error_In_Regexp : exception;
kono
parents:
diff changeset
107 -- Exception raised when an error is found in the regular expression
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 function Compile
kono
parents:
diff changeset
110 (Pattern : String;
kono
parents:
diff changeset
111 Glob : Boolean := False;
kono
parents:
diff changeset
112 Case_Sensitive : Boolean := True) return Regexp;
kono
parents:
diff changeset
113 -- Compiles a regular expression S. If the syntax of the given
kono
parents:
diff changeset
114 -- expression is invalid (does not match above grammar), Error_In_Regexp
kono
parents:
diff changeset
115 -- is raised. If Glob is True, the pattern is considered as a 'globbing
kono
parents:
diff changeset
116 -- pattern', that is a pattern as given by the second grammar above.
kono
parents:
diff changeset
117 -- As a special case, if Pattern is the empty string it will always
kono
parents:
diff changeset
118 -- match.
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 function Match (S : String; R : Regexp) return Boolean;
kono
parents:
diff changeset
121 -- True if S matches R, otherwise False. Raises Constraint_Error if
kono
parents:
diff changeset
122 -- R is an uninitialized regular expression value.
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 private
kono
parents:
diff changeset
125 type Regexp_Value;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 type Regexp_Access is access Regexp_Value;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 type Regexp is new Ada.Finalization.Controlled with record
kono
parents:
diff changeset
130 R : Regexp_Access := null;
kono
parents:
diff changeset
131 end record;
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 pragma Finalize_Storage_Only (Regexp);
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 procedure Finalize (R : in out Regexp);
kono
parents:
diff changeset
136 -- Free the memory occupied by R
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 procedure Adjust (R : in out Regexp);
kono
parents:
diff changeset
139 -- Called after an assignment (do a copy of the Regexp_Access.all)
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 end System.Regexp;