Chris@16
|
1 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 /// \file regex_constants.hpp
|
Chris@16
|
3 /// Contains definitions for the syntax_option_type, match_flag_type and
|
Chris@16
|
4 /// error_type enumerations.
|
Chris@16
|
5 //
|
Chris@16
|
6 // Copyright 2008 Eric Niebler. Distributed under the Boost
|
Chris@16
|
7 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
8 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9
|
Chris@16
|
10 #ifndef BOOST_XPRESSIVE_REGEX_CONSTANTS_HPP_EAN_10_04_2005
|
Chris@16
|
11 #define BOOST_XPRESSIVE_REGEX_CONSTANTS_HPP_EAN_10_04_2005
|
Chris@16
|
12
|
Chris@16
|
13 // MS compatible compilers support #pragma once
|
Chris@101
|
14 #if defined(_MSC_VER)
|
Chris@16
|
15 # pragma once
|
Chris@16
|
16 #endif
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/mpl/identity.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 #ifndef BOOST_XPRESSIVE_DOXYGEN_INVOKED
|
Chris@16
|
21 # define icase icase_
|
Chris@16
|
22 #endif
|
Chris@16
|
23
|
Chris@16
|
24 namespace boost { namespace xpressive { namespace regex_constants
|
Chris@16
|
25 {
|
Chris@16
|
26
|
Chris@16
|
27 /// Flags used to customize the regex syntax
|
Chris@16
|
28 ///
|
Chris@16
|
29 enum syntax_option_type
|
Chris@16
|
30 {
|
Chris@16
|
31 // these flags are required:
|
Chris@16
|
32
|
Chris@16
|
33 ECMAScript = 0, ///< Specifies that the grammar recognized by the regular expression
|
Chris@16
|
34 ///< engine uses its normal semantics: that is the same as that given
|
Chris@16
|
35 ///< in the ECMA-262, ECMAScript Language Specification, Chapter 15
|
Chris@16
|
36 ///< part 10, RegExp (Regular Expression) Objects (FWD.1).
|
Chris@16
|
37 ///<
|
Chris@16
|
38 icase = 1 << 1, ///< Specifies that matching of regular expressions against a character
|
Chris@16
|
39 ///< container sequence shall be performed without regard to case.
|
Chris@16
|
40 ///<
|
Chris@16
|
41 nosubs = 1 << 2, ///< Specifies that when a regular expression is matched against a
|
Chris@16
|
42 ///< character container sequence, then no sub-expression matches are to
|
Chris@16
|
43 ///< be stored in the supplied match_results structure.
|
Chris@16
|
44 ///<
|
Chris@16
|
45 optimize = 1 << 3, ///< Specifies that the regular expression engine should pay more
|
Chris@16
|
46 ///< attention to the speed with which regular expressions are matched,
|
Chris@16
|
47 ///< and less to the speed with which regular expression objects are
|
Chris@16
|
48 ///< constructed. Otherwise it has no detectable effect on the program
|
Chris@16
|
49 ///< output.
|
Chris@16
|
50 ///<
|
Chris@16
|
51 collate = 1 << 4, ///< Specifies that character ranges of the form "[a-b]" should be
|
Chris@16
|
52 ///< locale sensitive.
|
Chris@16
|
53 ///<
|
Chris@16
|
54
|
Chris@16
|
55 // These flags are optional. If the functionality is supported
|
Chris@16
|
56 // then the flags shall take these names.
|
Chris@16
|
57
|
Chris@16
|
58 //basic = 1 << 5, ///< Specifies that the grammar recognized by the regular expression
|
Chris@16
|
59 // ///< engine is the same as that used by POSIX basic regular expressions
|
Chris@16
|
60 // ///< in IEEE Std 1003.1-2001, Portable Operating System Interface
|
Chris@16
|
61 // ///< (POSIX), Base Definitions and Headers, Section 9, Regular
|
Chris@16
|
62 // ///< Expressions (FWD.1).
|
Chris@16
|
63 // ///<
|
Chris@16
|
64 //extended = 1 << 6, ///< Specifies that the grammar recognized by the regular expression
|
Chris@16
|
65 // ///< engine is the same as that used by POSIX extended regular
|
Chris@16
|
66 // ///< expressions in IEEE Std 1003.1-2001, Portable Operating System
|
Chris@16
|
67 // ///< Interface (POSIX), Base Definitions and Headers, Section 9,
|
Chris@16
|
68 // ///< Regular Expressions (FWD.1).
|
Chris@16
|
69 // ///<
|
Chris@16
|
70 //awk = 1 << 7, ///< Specifies that the grammar recognized by the regular expression
|
Chris@16
|
71 // ///< engine is the same as that used by POSIX utility awk in IEEE Std
|
Chris@16
|
72 // ///< 1003.1-2001, Portable Operating System Interface (POSIX), Shells
|
Chris@16
|
73 // ///< and Utilities, Section 4, awk (FWD.1).
|
Chris@16
|
74 // ///<
|
Chris@16
|
75 //grep = 1 << 8, ///< Specifies that the grammar recognized by the regular expression
|
Chris@16
|
76 // ///< engine is the same as that used by POSIX utility grep in IEEE Std
|
Chris@16
|
77 // ///< 1003.1-2001, Portable Operating System Interface (POSIX),
|
Chris@16
|
78 // ///< Shells and Utilities, Section 4, Utilities, grep (FWD.1).
|
Chris@16
|
79 // ///<
|
Chris@16
|
80 //egrep = 1 << 9, ///< Specifies that the grammar recognized by the regular expression
|
Chris@16
|
81 // ///< engine is the same as that used by POSIX utility grep when given
|
Chris@16
|
82 // ///< the -E option in IEEE Std 1003.1-2001, Portable Operating System
|
Chris@16
|
83 // ///< Interface (POSIX), Shells and Utilities, Section 4, Utilities,
|
Chris@16
|
84 // ///< grep (FWD.1).
|
Chris@16
|
85 // ///<
|
Chris@16
|
86
|
Chris@16
|
87 // these flags are specific to xpressive, and they help with perl compliance.
|
Chris@16
|
88
|
Chris@16
|
89 single_line = 1 << 10, ///< Specifies that the ^ and \$ metacharacters DO NOT match at
|
Chris@16
|
90 ///< internal line breaks. Note that this is the opposite of the
|
Chris@16
|
91 ///< perl default. It is the inverse of perl's /m (multi-line)
|
Chris@16
|
92 ///< modifier.
|
Chris@16
|
93 ///<
|
Chris@16
|
94 not_dot_null = 1 << 11, ///< Specifies that the . metacharacter does not match the null
|
Chris@16
|
95 ///< character \\0.
|
Chris@16
|
96 ///<
|
Chris@16
|
97 not_dot_newline = 1 << 12, ///< Specifies that the . metacharacter does not match the
|
Chris@16
|
98 ///< newline character \\n.
|
Chris@16
|
99 ///<
|
Chris@16
|
100 ignore_white_space = 1 << 13 ///< Specifies that non-escaped white-space is not significant.
|
Chris@16
|
101 ///<
|
Chris@16
|
102 };
|
Chris@16
|
103
|
Chris@16
|
104 /// Flags used to customize the behavior of the regex algorithms
|
Chris@16
|
105 ///
|
Chris@16
|
106 enum match_flag_type
|
Chris@16
|
107 {
|
Chris@16
|
108 match_default = 0, ///< Specifies that matching of regular expressions proceeds
|
Chris@16
|
109 ///< without any modification of the normal rules used in
|
Chris@16
|
110 ///< ECMA-262, ECMAScript Language Specification, Chapter 15
|
Chris@16
|
111 ///< part 10, RegExp (Regular Expression) Objects (FWD.1)
|
Chris@16
|
112 ///<
|
Chris@16
|
113 match_not_bol = 1 << 1, ///< Specifies that the expression "^" should not be matched
|
Chris@16
|
114 ///< against the sub-sequence [first,first).
|
Chris@16
|
115 ///<
|
Chris@16
|
116 match_not_eol = 1 << 2, ///< Specifies that the expression "\$" should not be
|
Chris@16
|
117 ///< matched against the sub-sequence [last,last).
|
Chris@16
|
118 ///<
|
Chris@16
|
119 match_not_bow = 1 << 3, ///< Specifies that the expression "\\b" should not be
|
Chris@16
|
120 ///< matched against the sub-sequence [first,first).
|
Chris@16
|
121 ///<
|
Chris@16
|
122 match_not_eow = 1 << 4, ///< Specifies that the expression "\\b" should not be
|
Chris@16
|
123 ///< matched against the sub-sequence [last,last).
|
Chris@16
|
124 ///<
|
Chris@16
|
125 match_any = 1 << 7, ///< Specifies that if more than one match is possible then
|
Chris@16
|
126 ///< any match is an acceptable result.
|
Chris@16
|
127 ///<
|
Chris@16
|
128 match_not_null = 1 << 8, ///< Specifies that the expression can not be matched
|
Chris@16
|
129 ///< against an empty sequence.
|
Chris@16
|
130 ///<
|
Chris@16
|
131 match_continuous = 1 << 10, ///< Specifies that the expression must match a sub-sequence
|
Chris@16
|
132 ///< that begins at first.
|
Chris@16
|
133 ///<
|
Chris@16
|
134 match_partial = 1 << 11, ///< Specifies that if no match can be found, then it is
|
Chris@16
|
135 ///< acceptable to return a match [from, last) where
|
Chris@16
|
136 ///< from != last, if there exists some sequence of characters
|
Chris@16
|
137 ///< [from,to) of which [from,last) is a prefix, and which
|
Chris@16
|
138 ///< would result in a full match.
|
Chris@16
|
139 ///<
|
Chris@16
|
140 match_prev_avail = 1 << 12, ///< Specifies that --first is a valid iterator position,
|
Chris@16
|
141 ///< when this flag is set then the flags match_not_bol
|
Chris@16
|
142 ///< and match_not_bow are ignored by the regular expression
|
Chris@16
|
143 ///< algorithms (RE.7) and iterators (RE.8).
|
Chris@16
|
144 ///<
|
Chris@16
|
145 format_default = 0, ///< Specifies that when a regular expression match is to be
|
Chris@16
|
146 ///< replaced by a new string, that the new string is
|
Chris@16
|
147 ///< constructed using the rules used by the ECMAScript
|
Chris@16
|
148 ///< replace function in ECMA-262, ECMAScript Language
|
Chris@16
|
149 ///< Specification, Chapter 15 part 5.4.11
|
Chris@16
|
150 ///< String.prototype.replace. (FWD.1). In addition during
|
Chris@16
|
151 ///< search and replace operations then all non-overlapping
|
Chris@16
|
152 ///< occurrences of the regular expression are located and
|
Chris@16
|
153 ///< replaced, and sections of the input that did not match
|
Chris@16
|
154 ///< the expression, are copied unchanged to the output
|
Chris@16
|
155 ///< string.
|
Chris@16
|
156 ///<
|
Chris@16
|
157 format_sed = 1 << 13, ///< Specifies that when a regular expression match is to be
|
Chris@16
|
158 ///< replaced by a new string, that the new string is
|
Chris@16
|
159 ///< constructed using the rules used by the Unix sed
|
Chris@16
|
160 ///< utility in IEEE Std 1003.1-2001, Portable Operating
|
Chris@16
|
161 ///< SystemInterface (POSIX), Shells and Utilities.
|
Chris@16
|
162 ///<
|
Chris@16
|
163 format_perl = 1 << 14, ///< Specifies that when a regular expression match is to be
|
Chris@16
|
164 ///< replaced by a new string, that the new string is
|
Chris@16
|
165 ///< constructed using an implementation defined superset
|
Chris@16
|
166 ///< of the rules used by the ECMAScript replace function in
|
Chris@16
|
167 ///< ECMA-262, ECMAScript Language Specification, Chapter 15
|
Chris@16
|
168 ///< part 5.4.11 String.prototype.replace (FWD.1).
|
Chris@16
|
169 ///<
|
Chris@16
|
170 format_no_copy = 1 << 15, ///< When specified during a search and replace operation,
|
Chris@16
|
171 ///< then sections of the character container sequence being
|
Chris@16
|
172 ///< searched that do match the regular expression, are not
|
Chris@16
|
173 ///< copied to the output string.
|
Chris@16
|
174 ///<
|
Chris@16
|
175 format_first_only = 1 << 16, ///< When specified during a search and replace operation,
|
Chris@16
|
176 ///< then only the first occurrence of the regular
|
Chris@16
|
177 ///< expression is replaced.
|
Chris@16
|
178 ///<
|
Chris@16
|
179 format_literal = 1 << 17, ///< Treat the format string as a literal.
|
Chris@16
|
180 ///<
|
Chris@16
|
181 format_all = 1 << 18 ///< Specifies that all syntax extensions are enabled,
|
Chris@16
|
182 ///< including conditional (?ddexpression1:expression2)
|
Chris@16
|
183 ///< replacements.
|
Chris@16
|
184 ///<
|
Chris@16
|
185 };
|
Chris@16
|
186
|
Chris@16
|
187 /// Error codes used by the regex_error type
|
Chris@16
|
188 ///
|
Chris@16
|
189 enum error_type
|
Chris@16
|
190 {
|
Chris@16
|
191 error_collate, ///< The expression contained an invalid collating element name.
|
Chris@16
|
192 ///<
|
Chris@16
|
193 error_ctype, ///< The expression contained an invalid character class name.
|
Chris@16
|
194 ///<
|
Chris@16
|
195 error_escape, ///< The expression contained an invalid escaped character,
|
Chris@16
|
196 ///< or a trailing escape.
|
Chris@16
|
197 ///<
|
Chris@16
|
198 error_subreg, ///< The expression contained an invalid back-reference.
|
Chris@16
|
199 ///<
|
Chris@16
|
200 error_brack, ///< The expression contained mismatched [ and ].
|
Chris@16
|
201 ///<
|
Chris@16
|
202 error_paren, ///< The expression contained mismatched ( and ).
|
Chris@16
|
203 ///<
|
Chris@16
|
204 error_brace, ///< The expression contained mismatched { and }.
|
Chris@16
|
205 ///<
|
Chris@16
|
206 error_badbrace, ///< The expression contained an invalid range in a {} expression.
|
Chris@16
|
207 ///<
|
Chris@16
|
208 error_range, ///< The expression contained an invalid character range, for
|
Chris@16
|
209 ///< example [b-a].
|
Chris@16
|
210 ///<
|
Chris@16
|
211 error_space, ///< There was insufficient memory to convert the expression into a
|
Chris@16
|
212 ///< finite state machine.
|
Chris@16
|
213 ///<
|
Chris@16
|
214 error_badrepeat, ///< One of *?+{ was not preceded by a valid regular expression.
|
Chris@16
|
215 ///<
|
Chris@16
|
216 error_complexity, ///< The complexity of an attempted match against a regular
|
Chris@16
|
217 ///< expression exceeded a pre-set level.
|
Chris@16
|
218 ///<
|
Chris@16
|
219 error_stack, ///< There was insufficient memory to determine whether the regular
|
Chris@16
|
220 ///< expression could match the specified character sequence.
|
Chris@16
|
221 ///<
|
Chris@16
|
222 error_badref, ///< An nested regex is uninitialized.
|
Chris@16
|
223 ///<
|
Chris@16
|
224 error_badmark, ///< An invalid use of a named capture.
|
Chris@16
|
225 ///<
|
Chris@16
|
226 error_badlookbehind, ///< An attempt to create a variable-width look-behind assertion
|
Chris@16
|
227 ///< was detected.
|
Chris@16
|
228 ///<
|
Chris@16
|
229 error_badrule, ///< An invalid use of a rule was detected.
|
Chris@16
|
230 ///<
|
Chris@16
|
231 error_badarg, ///< An argument to an action was unbound.
|
Chris@16
|
232 ///<
|
Chris@16
|
233 error_badattr, ///< Tried to read from an uninitialized attribute.
|
Chris@16
|
234 ///<
|
Chris@16
|
235 error_internal ///< An internal error has occurred.
|
Chris@16
|
236 ///<
|
Chris@16
|
237 };
|
Chris@16
|
238
|
Chris@16
|
239 /// INTERNAL ONLY
|
Chris@16
|
240 inline syntax_option_type operator &(syntax_option_type b1, syntax_option_type b2)
|
Chris@16
|
241 {
|
Chris@16
|
242 return static_cast<syntax_option_type>(
|
Chris@16
|
243 static_cast<int>(b1) & static_cast<int>(b2));
|
Chris@16
|
244 }
|
Chris@16
|
245
|
Chris@16
|
246 /// INTERNAL ONLY
|
Chris@16
|
247 inline syntax_option_type operator |(syntax_option_type b1, syntax_option_type b2)
|
Chris@16
|
248 {
|
Chris@16
|
249 return static_cast<syntax_option_type>(static_cast<int>(b1) | static_cast<int>(b2));
|
Chris@16
|
250 }
|
Chris@16
|
251
|
Chris@16
|
252 /// INTERNAL ONLY
|
Chris@16
|
253 inline syntax_option_type operator ^(syntax_option_type b1, syntax_option_type b2)
|
Chris@16
|
254 {
|
Chris@16
|
255 return static_cast<syntax_option_type>(static_cast<int>(b1) ^ static_cast<int>(b2));
|
Chris@16
|
256 }
|
Chris@16
|
257
|
Chris@16
|
258 /// INTERNAL ONLY
|
Chris@16
|
259 inline syntax_option_type operator ~(syntax_option_type b)
|
Chris@16
|
260 {
|
Chris@16
|
261 return static_cast<syntax_option_type>(~static_cast<int>(b));
|
Chris@16
|
262 }
|
Chris@16
|
263
|
Chris@16
|
264 /// INTERNAL ONLY
|
Chris@16
|
265 inline match_flag_type operator &(match_flag_type b1, match_flag_type b2)
|
Chris@16
|
266 {
|
Chris@16
|
267 return static_cast<match_flag_type>(static_cast<int>(b1) & static_cast<int>(b2));
|
Chris@16
|
268 }
|
Chris@16
|
269
|
Chris@16
|
270 /// INTERNAL ONLY
|
Chris@16
|
271 inline match_flag_type operator |(match_flag_type b1, match_flag_type b2)
|
Chris@16
|
272 {
|
Chris@16
|
273 return static_cast<match_flag_type>(static_cast<int>(b1) | static_cast<int>(b2));
|
Chris@16
|
274 }
|
Chris@16
|
275
|
Chris@16
|
276 /// INTERNAL ONLY
|
Chris@16
|
277 inline match_flag_type operator ^(match_flag_type b1, match_flag_type b2)
|
Chris@16
|
278 {
|
Chris@16
|
279 return static_cast<match_flag_type>(static_cast<int>(b1) ^ static_cast<int>(b2));
|
Chris@16
|
280 }
|
Chris@16
|
281
|
Chris@16
|
282 /// INTERNAL ONLY
|
Chris@16
|
283 inline match_flag_type operator ~(match_flag_type b)
|
Chris@16
|
284 {
|
Chris@16
|
285 return static_cast<match_flag_type>(~static_cast<int>(b));
|
Chris@16
|
286 }
|
Chris@16
|
287
|
Chris@16
|
288 }}} // namespace boost::xpressive::regex_constants
|
Chris@16
|
289
|
Chris@16
|
290 #ifndef BOOST_XPRESSIVE_DOXYGEN_INVOKED
|
Chris@16
|
291 # undef icase
|
Chris@16
|
292 #endif
|
Chris@16
|
293
|
Chris@16
|
294 #endif
|