as_marker.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // as_marker.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_MARKER_HPP_EAN_04_01_2007
  8. #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MARKER_HPP_EAN_04_01_2007
  9. // MS compatible compilers support #pragma once
  10. #if defined(_MSC_VER)
  11. # pragma once
  12. #endif
  13. #include <boost/xpressive/detail/detail_fwd.hpp>
  14. #include <boost/xpressive/detail/static/static.hpp>
  15. #include <boost/proto/core.hpp>
  16. namespace boost { namespace xpressive { namespace grammar_detail
  17. {
  18. ///////////////////////////////////////////////////////////////////////////////
  19. // as_marker
  20. // Insert mark tags before and after the expression
  21. struct as_marker : proto::transform<as_marker>
  22. {
  23. template<typename Expr, typename State, typename Data>
  24. struct impl : proto::transform_impl<Expr, State, Data>
  25. {
  26. typedef
  27. typename shift_right<
  28. terminal<detail::mark_begin_matcher>::type
  29. , typename shift_right<
  30. typename proto::result_of::right<typename impl::expr>::type
  31. , terminal<detail::mark_end_matcher>::type
  32. >::type
  33. >::type
  34. result_type;
  35. result_type operator ()(
  36. typename impl::expr_param expr
  37. , typename impl::state_param
  38. , typename impl::data_param
  39. ) const
  40. {
  41. int mark_nbr = detail::get_mark_number(proto::left(expr));
  42. detail::mark_begin_matcher begin(mark_nbr);
  43. detail::mark_end_matcher end(mark_nbr);
  44. result_type that = {{begin}, {proto::right(expr), {end}}};
  45. return that;
  46. }
  47. };
  48. };
  49. }}}
  50. #endif