as_modifier.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // as_modifier.hpp
  3. //
  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)
  7. #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MODIFIER_HPP_EAN_04_05_2007
  8. #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MODIFIER_HPP_EAN_04_05_2007
  9. // MS compatible compilers support #pragma once
  10. #if defined(_MSC_VER)
  11. # pragma once
  12. #endif
  13. #include <boost/mpl/sizeof.hpp>
  14. #include <boost/xpressive/detail/detail_fwd.hpp>
  15. #include <boost/xpressive/detail/static/static.hpp>
  16. #include <boost/proto/core.hpp>
  17. #define UNCV(x) typename remove_const<x>::type
  18. #define UNREF(x) typename remove_reference<x>::type
  19. #define UNCVREF(x) UNCV(UNREF(x))
  20. namespace boost { namespace xpressive { namespace detail
  21. {
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // regex operator tags
  24. struct modifier_tag
  25. {};
  26. }}}
  27. namespace boost { namespace xpressive { namespace grammar_detail
  28. {
  29. ///////////////////////////////////////////////////////////////////////////////
  30. // as_modifier
  31. template<typename Grammar, typename Callable = proto::callable>
  32. struct as_modifier : proto::transform<as_modifier<Grammar, Callable> >
  33. {
  34. template<typename Expr, typename State, typename Data>
  35. struct impl : proto::transform_impl<Expr, State, Data>
  36. {
  37. typedef
  38. typename proto::result_of::value<
  39. typename proto::result_of::left<typename impl::expr>::type
  40. >::type
  41. modifier_type;
  42. typedef
  43. typename modifier_type::template apply<typename impl::data>::type
  44. visitor_type;
  45. typedef
  46. typename proto::result_of::right<Expr>::type
  47. expr_type;
  48. typedef
  49. typename Grammar::template impl<expr_type, State, visitor_type &>::result_type
  50. result_type;
  51. result_type operator ()(
  52. typename impl::expr_param expr
  53. , typename impl::state_param state
  54. , typename impl::data_param data
  55. ) const
  56. {
  57. visitor_type new_visitor(proto::value(proto::left(expr)).call(data));
  58. return typename Grammar::template impl<expr_type, State, visitor_type &>()(
  59. proto::right(expr)
  60. , state
  61. , new_visitor
  62. );
  63. }
  64. };
  65. };
  66. }}}
  67. #undef UNCV
  68. #undef UNREF
  69. #undef UNCVREF
  70. #endif