regex.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*=============================================================================
  2. Copyright (c) 2002-2003 Hartmut Kaiser
  3. http://spirit.sourceforge.net/
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #ifndef BOOST_SPIRIT_REGEX_HPP
  8. #define BOOST_SPIRIT_REGEX_HPP
  9. #include <boost/version.hpp>
  10. ///////////////////////////////////////////////////////////////////////////////
  11. //
  12. // Include the regular expression library of boost (Boost.Regex)
  13. //
  14. // Note though, that this library is not distributed with Spirit. You have to
  15. // obtain a separate copy from http://www.boost.org.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #if defined(BOOST_SPIRIT_NO_REGEX_LIB) && BOOST_VERSION < 103300
  19. //
  20. // Include all the Boost.regex library. Please note that this will not work,
  21. // if you are using the boost/spirit/regex.hpp header from more than one
  22. // translation units.
  23. //
  24. #define BOOST_REGEX_NO_LIB
  25. #define BOOST_REGEX_STATIC_LINK
  26. #define BOOST_REGEX_NO_EXTERNAL_TEMPLATES
  27. #include <boost/regex.hpp>
  28. #include <boost/regex/src.cpp>
  29. #else
  30. //
  31. // Include the Boost.Regex headers only. Note, that you will have to link your
  32. // application against the Boost.Regex library as described in the related
  33. // documentation.
  34. // This is the only way for Boost newer than V1.32.0
  35. //
  36. #include <boost/regex.hpp>
  37. #endif // defined(BOOST_SPIRIT_NO_REGEX_LIB)
  38. #include <boost/static_assert.hpp>
  39. ///////////////////////////////////////////////////////////////////////////////
  40. #include <boost/spirit/home/classic/namespace.hpp>
  41. #include <boost/spirit/home/classic/meta/as_parser.hpp>
  42. #include <boost/spirit/home/classic/core/parser.hpp>
  43. #include <boost/spirit/home/classic/utility/impl/regex.ipp>
  44. #include <iterator> // for std::iterator_traits
  45. ///////////////////////////////////////////////////////////////////////////////
  46. namespace boost { namespace spirit {
  47. BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
  48. ///////////////////////////////////////////////////////////////////////////////
  49. // rxstrlit class
  50. template <typename CharT = char>
  51. struct rxstrlit : public parser<rxstrlit<CharT> > {
  52. typedef rxstrlit self_t;
  53. rxstrlit(CharT const *first, CharT const *last)
  54. : rx(first, last) {}
  55. rxstrlit(CharT const *first)
  56. : rx(first) {}
  57. template <typename ScannerT>
  58. typename parser_result<self_t, ScannerT>::type
  59. parse(ScannerT const& scan) const
  60. {
  61. // Due to limitations in the boost::regex library the iterators wrapped in
  62. // the ScannerT object should be at least bidirectional iterators. Plain
  63. // forward iterators do not work here.
  64. typedef typename ScannerT::iterator_t iterator_t;
  65. typedef
  66. typename std::iterator_traits<iterator_t>::iterator_category
  67. iterator_category;
  68. BOOST_STATIC_ASSERT((
  69. boost::is_convertible<iterator_category,
  70. std::bidirectional_iterator_tag>::value
  71. ));
  72. typedef typename parser_result<self_t, ScannerT>::type result_t;
  73. return impl::contiguous_parser_parse<result_t>(rx, scan, scan);
  74. }
  75. private:
  76. impl::rx_parser<CharT> rx; // contains the boost regular expression parser
  77. };
  78. ///////////////////////////////////////////////////////////////////////////////
  79. // Generator functions
  80. template <typename CharT>
  81. inline rxstrlit<CharT>
  82. regex_p(CharT const *first)
  83. { return rxstrlit<CharT>(first); }
  84. //////////////////////////////////
  85. template <typename CharT>
  86. inline rxstrlit<CharT>
  87. regex_p(CharT const *first, CharT const *last)
  88. { return rxstrlit<CharT>(first, last); }
  89. ///////////////////////////////////////////////////////////////////////////////
  90. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  91. }} // namespace BOOST_SPIRIT_CLASSIC_NS
  92. #endif // BOOST_SPIRIT_REGEX_HPP