1 /*=============================================================================
2 Copyright (c) 2002-2003 Hartmut Kaiser
3 http://spirit.sourceforge.net/
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #ifndef BOOST_SPIRIT_REGEX_HPP
9 #define BOOST_SPIRIT_REGEX_HPP
11 #include <boost/version.hpp>
13 ///////////////////////////////////////////////////////////////////////////////
15 // Include the regular expression library of boost (Boost.Regex)
17 // Note though, that this library is not distributed with Spirit. You have to
18 // obtain a separate copy from http://www.boost.org.
20 ///////////////////////////////////////////////////////////////////////////////
21 #if defined(BOOST_SPIRIT_NO_REGEX_LIB) && BOOST_VERSION < 103300
23 // Include all the Boost.regex library. Please note that this will not work,
24 // if you are using the boost/spirit/regex.hpp header from more than one
27 #define BOOST_REGEX_NO_LIB
28 #define BOOST_REGEX_STATIC_LINK
29 #define BOOST_REGEX_NO_EXTERNAL_TEMPLATES
30 #include <boost/regex.hpp>
31 #include <boost/regex/src.cpp>
35 // Include the Boost.Regex headers only. Note, that you will have to link your
36 // application against the Boost.Regex library as described in the related
38 // This is the only way for Boost newer than V1.32.0
40 #include <boost/regex.hpp>
41 #endif // defined(BOOST_SPIRIT_NO_REGEX_LIB)
43 #include <boost/static_assert.hpp>
45 ///////////////////////////////////////////////////////////////////////////////
46 #include <boost/spirit/home/classic/namespace.hpp>
47 #include <boost/spirit/home/classic/meta/as_parser.hpp>
48 #include <boost/spirit/home/classic/core/parser.hpp>
49 #include <boost/spirit/home/classic/utility/impl/regex.ipp>
50 #include <boost/detail/iterator.hpp> // for boost::detail::iterator_traits
52 ///////////////////////////////////////////////////////////////////////////////
53 namespace boost { namespace spirit {
55 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
57 ///////////////////////////////////////////////////////////////////////////////
59 template <typename CharT = char>
60 struct rxstrlit : public parser<rxstrlit<CharT> > {
62 typedef rxstrlit self_t;
64 rxstrlit(CharT const *first, CharT const *last)
66 rxstrlit(CharT const *first)
69 template <typename ScannerT>
70 typename parser_result<self_t, ScannerT>::type
71 parse(ScannerT const& scan) const
73 // Due to limitations in the boost::regex library the iterators wrapped in
74 // the ScannerT object should be at least bidirectional iterators. Plain
75 // forward iterators do not work here.
76 typedef typename ScannerT::iterator_t iterator_t;
78 typename boost::detail::iterator_traits<iterator_t>::iterator_category
82 boost::is_convertible<iterator_category,
83 std::bidirectional_iterator_tag>::value
86 typedef typename parser_result<self_t, ScannerT>::type result_t;
87 return impl::contiguous_parser_parse<result_t>(rx, scan, scan);
91 impl::rx_parser<CharT> rx; // contains the boost regular expression parser
94 ///////////////////////////////////////////////////////////////////////////////
95 // Generator functions
96 template <typename CharT>
97 inline rxstrlit<CharT>
98 regex_p(CharT const *first)
99 { return rxstrlit<CharT>(first); }
101 //////////////////////////////////
102 template <typename CharT>
103 inline rxstrlit<CharT>
104 regex_p(CharT const *first, CharT const *last)
105 { return rxstrlit<CharT>(first, last); }
107 ///////////////////////////////////////////////////////////////////////////////
108 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
110 }} // namespace BOOST_SPIRIT_CLASSIC_NS
112 #endif // BOOST_SPIRIT_REGEX_HPP