skip.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*=============================================================================
  2. Copyright (c) 2001-2014 Joel de Guzman
  3. Copyright (c) 2013 Agustin Berge
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #if !defined(BOOST_SPIRIT_X3_SKIP_JANUARY_26_2008_0422PM)
  8. #define BOOST_SPIRIT_X3_SKIP_JANUARY_26_2008_0422PM
  9. #include <boost/spirit/home/x3/support/context.hpp>
  10. #include <boost/spirit/home/x3/support/unused.hpp>
  11. #include <boost/spirit/home/x3/core/skip_over.hpp>
  12. #include <boost/spirit/home/x3/core/parser.hpp>
  13. #include <boost/utility/enable_if.hpp>
  14. namespace boost { namespace spirit { namespace x3
  15. {
  16. template <typename Subject>
  17. struct reskip_directive : unary_parser<Subject, reskip_directive<Subject>>
  18. {
  19. typedef unary_parser<Subject, reskip_directive<Subject>> base_type;
  20. static bool const is_pass_through_unary = true;
  21. static bool const handles_container = Subject::handles_container;
  22. constexpr reskip_directive(Subject const& subject)
  23. : base_type(subject) {}
  24. template <typename Iterator, typename Context
  25. , typename RContext, typename Attribute>
  26. typename disable_if<has_skipper<Context>, bool>::type
  27. parse(Iterator& first, Iterator const& last
  28. , Context const& context, RContext& rcontext, Attribute& attr) const
  29. {
  30. auto const& skipper =
  31. detail::get_unused_skipper(x3::get<skipper_tag>(context));
  32. return this->subject.parse(
  33. first, last
  34. , make_context<skipper_tag>(skipper, context)
  35. , rcontext
  36. , attr);
  37. }
  38. template <typename Iterator, typename Context
  39. , typename RContext, typename Attribute>
  40. typename enable_if<has_skipper<Context>, bool>::type
  41. parse(Iterator& first, Iterator const& last
  42. , Context const& context, RContext& rcontext, Attribute& attr) const
  43. {
  44. return this->subject.parse(
  45. first, last
  46. , context
  47. , rcontext
  48. , attr);
  49. }
  50. };
  51. template <typename Subject, typename Skipper>
  52. struct skip_directive : unary_parser<Subject, skip_directive<Subject, Skipper>>
  53. {
  54. typedef unary_parser<Subject, skip_directive<Subject, Skipper>> base_type;
  55. static bool const is_pass_through_unary = true;
  56. static bool const handles_container = Subject::handles_container;
  57. constexpr skip_directive(Subject const& subject, Skipper const& skipper)
  58. : base_type(subject)
  59. , skipper(skipper)
  60. {}
  61. template <typename Iterator, typename Context
  62. , typename RContext, typename Attribute>
  63. bool parse(Iterator& first, Iterator const& last
  64. , Context const& context, RContext& rcontext, Attribute& attr) const
  65. {
  66. return this->subject.parse(
  67. first, last
  68. , make_context<skipper_tag>(skipper, context)
  69. , rcontext
  70. , attr);
  71. }
  72. Skipper const skipper;
  73. };
  74. struct reskip_gen
  75. {
  76. template <typename Skipper>
  77. struct skip_gen
  78. {
  79. constexpr skip_gen(Skipper const& skipper)
  80. : skipper_(skipper) {}
  81. template <typename Subject>
  82. constexpr skip_directive<typename extension::as_parser<Subject>::value_type, Skipper>
  83. operator[](Subject const& subject) const
  84. {
  85. return { as_parser(subject), skipper_ };
  86. }
  87. Skipper skipper_;
  88. };
  89. template <typename Skipper>
  90. constexpr skip_gen<Skipper> const operator()(Skipper const& skipper) const
  91. {
  92. return { skipper };
  93. }
  94. template <typename Subject>
  95. constexpr reskip_directive<typename extension::as_parser<Subject>::value_type>
  96. operator[](Subject const& subject) const
  97. {
  98. return { as_parser(subject) };
  99. }
  100. };
  101. constexpr auto skip = reskip_gen{};
  102. }}}
  103. #endif