regex_constants.hpp 16 KB

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