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_IPP
10 #define BOOST_SPIRIT_REGEX_IPP
12 ///////////////////////////////////////////////////////////////////////////////
13 #include <boost/spirit/home/classic/core/primitives/impl/primitives.ipp>
15 ///////////////////////////////////////////////////////////////////////////////
16 namespace boost { namespace spirit {
18 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
22 ///////////////////////////////////////////////////////////////////////////////
24 inline const char* rx_prefix(char) { return "\\A"; }
25 inline const wchar_t* rx_prefix(wchar_t) { return L"\\A"; }
27 ///////////////////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////////////////
32 template <typename CharT = char>
33 class rx_parser : public parser<rx_parser<CharT> > {
36 typedef std::basic_string<CharT> string_t;
37 typedef rx_parser<CharT> self_t;
39 rx_parser(CharT const *first, CharT const *last)
41 rxstr = string_t(rx_prefix(CharT())) + string_t(first, last);
44 rx_parser(CharT const *first)
46 rxstr = string_t(rx_prefix(CharT())) +
47 string_t(first, impl::get_last(first));
50 template <typename ScannerT>
51 typename parser_result<self_t, ScannerT>::type
52 parse(ScannerT const& scan) const
54 boost::match_results<typename ScannerT::iterator_t> what;
55 boost::regex_search(scan.first, scan.last, what, rxstr,
56 boost::match_default);
59 return scan.no_match();
61 scan.first = what[0].second;
62 return scan.create_match(what[0].length(), nil_t(),
63 what[0].first, scan.first);
67 #if BOOST_VERSION >= 013300
68 boost::basic_regex<CharT> rxstr; // regular expression to match
70 boost::reg_expression<CharT> rxstr; // regular expression to match
76 ///////////////////////////////////////////////////////////////////////////////
77 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
79 }} // namespace boost::spirit
81 #endif // BOOST_SPIRIT_REGEX_IPP