First public contribution.
1 /*=============================================================================
2 Copyright (c) 2002-2003 Hartmut Kaiser
3 http://spirit.sourceforge.net/
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #ifndef BOOST_SPIRIT_REGEX_HPP
10 #define BOOST_SPIRIT_REGEX_HPP
12 #include <boost/version.hpp>
14 ///////////////////////////////////////////////////////////////////////////////
16 // Include the regular expression library of boost (Boost.Regex)
18 // Note though, that this library is not distributed with Spirit. You have to
19 // obtain a separate copy from http://www.boost.org.
21 ///////////////////////////////////////////////////////////////////////////////
22 #if defined(BOOST_SPIRIT_NO_REGEX_LIB) && BOOST_VERSION < 103300
24 // Include all the Boost.regex library. Please note that this will not work,
25 // if you are using the boost/spirit/regex.hpp header from more than one
28 #define BOOST_REGEX_NO_LIB
29 #define BOOST_REGEX_STATIC_LINK
30 #define BOOST_REGEX_NO_EXTERNAL_TEMPLATES
31 #include <boost/regex.hpp>
32 #include <boost/regex/src.cpp>
36 // Include the Boost.Regex headers only. Note, that you will have to link your
37 // application against the Boost.Regex library as described in the related
39 // This is the only way for Boost newer than V1.32.0
41 #include <boost/regex.hpp>
42 #endif // defined(BOOST_SPIRIT_NO_REGEX_LIB)
44 #include <boost/static_assert.hpp>
46 ///////////////////////////////////////////////////////////////////////////////
47 #include <boost/spirit/meta/as_parser.hpp>
48 #include <boost/spirit/core/parser.hpp>
49 #include <boost/spirit/utility/impl/regex.ipp>
50 #include <boost/detail/iterator.hpp> // for boost::detail::iterator_traits
52 ///////////////////////////////////////////////////////////////////////////////
53 namespace boost { namespace spirit {
55 ///////////////////////////////////////////////////////////////////////////////
57 template <typename CharT = char>
58 struct rxstrlit : public parser<rxstrlit<CharT> > {
60 typedef rxstrlit self_t;
62 rxstrlit(CharT const *first, CharT const *last)
64 rxstrlit(CharT const *first)
67 template <typename ScannerT>
68 typename parser_result<self_t, ScannerT>::type
69 parse(ScannerT const& scan) const
71 // Due to limitations in the boost::regex library the iterators wrapped in
72 // the ScannerT object should be at least bidirectional iterators. Plain
73 // forward iterators do not work here.
74 typedef typename ScannerT::iterator_t iterator_t;
76 typename boost::detail::iterator_traits<iterator_t>::iterator_category
80 boost::is_convertible<iterator_category,
81 std::bidirectional_iterator_tag>::value
84 typedef typename parser_result<self_t, ScannerT>::type result_t;
85 return impl::contiguous_parser_parse<result_t>(rx, scan, scan);
89 impl::rx_parser<CharT> rx; // contains the boost regular expression parser
92 ///////////////////////////////////////////////////////////////////////////////
93 // Generator functions
94 template <typename CharT>
95 inline rxstrlit<CharT>
96 regex_p(CharT const *first)
97 { return rxstrlit<CharT>(first); }
99 //////////////////////////////////
100 template <typename CharT>
101 inline rxstrlit<CharT>
102 regex_p(CharT const *first, CharT const *last)
103 { return rxstrlit<CharT>(first, last); }
105 ///////////////////////////////////////////////////////////////////////////////
106 }} // namespace boost::spirit
108 #endif // BOOST_SPIRIT_REGEX_HPP