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