1 ///////////////////////////////////////////////////////////////////////////////
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_COMPILE_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_STATIC_COMPILE_HPP_EAN_10_04_2005
11 // MS compatible compilers support #pragma once
12 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
16 #include <boost/mpl/bool.hpp>
17 #include <boost/iterator/iterator_traits.hpp>
18 #include <boost/proto/core.hpp>
19 #include <boost/xpressive/regex_traits.hpp>
20 #include <boost/xpressive/detail/core/regex_impl.hpp>
21 #include <boost/xpressive/detail/core/linker.hpp>
22 #include <boost/xpressive/detail/core/optimize.hpp>
23 #include <boost/xpressive/detail/core/adaptor.hpp>
24 #include <boost/xpressive/detail/core/matcher/end_matcher.hpp>
25 #include <boost/xpressive/detail/static/static.hpp>
26 #include <boost/xpressive/detail/static/visitor.hpp>
27 #include <boost/xpressive/detail/static/grammar.hpp>
29 namespace boost { namespace xpressive { namespace detail
32 ///////////////////////////////////////////////////////////////////////////////
33 // static_compile_impl2
34 template<typename Xpr, typename BidiIter, typename Traits>
35 void static_compile_impl2(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl, Traits const &tr)
37 typedef typename iterator_value<BidiIter>::type char_type;
38 impl->tracking_clear();
39 impl->traits_ = new traits_holder<Traits>(tr);
41 // "compile" the regex and wrap it in an xpression_adaptor.
42 typedef xpression_visitor<BidiIter, mpl::false_, Traits> visitor_type;
43 visitor_type visitor(tr, impl);
44 intrusive_ptr<matchable_ex<BidiIter> const> adxpr = make_adaptor<matchable_ex<BidiIter> >(
45 typename Grammar<char_type>::template impl<Xpr const &, end_xpression, visitor_type &>()(
52 // Link and optimize the regex
53 common_compile(adxpr, *impl, visitor.traits());
55 // References changed, update dependencies.
56 impl->tracking_update();
59 ///////////////////////////////////////////////////////////////////////////////
60 // pattern for imbued regexes.
61 struct XpressiveLocaleModifier
64 , proto::terminal<locale_modifier<proto::_> >
69 ///////////////////////////////////////////////////////////////////////////////
70 // static_compile_impl1
71 template<typename Xpr, typename BidiIter>
72 typename disable_if<proto::matches<Xpr, XpressiveLocaleModifier> >::type
73 static_compile_impl1(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl)
76 typedef typename iterator_value<BidiIter>::type char_type;
77 typedef typename default_regex_traits<char_type>::type traits_type;
79 static_compile_impl2(xpr, impl, tr);
82 ///////////////////////////////////////////////////////////////////////////////
83 // static_compile_impl1
84 template<typename Xpr, typename BidiIter>
85 typename enable_if<proto::matches<Xpr, XpressiveLocaleModifier> >::type
86 static_compile_impl1(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl)
88 // use specified traits
89 typedef typename proto::result_of::value<typename proto::result_of::left<Xpr>::type>::type::locale_type locale_type;
90 typedef typename regex_traits_type<locale_type, BidiIter>::type traits_type;
91 static_compile_impl2(proto::right(xpr), impl, traits_type(proto::value(proto::left(xpr)).getloc()));
94 ///////////////////////////////////////////////////////////////////////////////
96 template<typename Xpr, typename BidiIter>
97 void static_compile(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl)
99 static_compile_impl1(xpr, impl);
102 }}} // namespace boost::xpressive::detail