no_skip.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*=============================================================================
  2. Copyright (c) 2001-2014 Joel de Guzman
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  4. Copyright (c) 2013 Agustin Berge
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #if !defined(BOOST_SPIRIT_X3_NO_SKIP_JAN_16_2010_0802PM)
  9. #define BOOST_SPIRIT_X3_NO_SKIP_JAN_16_2010_0802PM
  10. #include <boost/spirit/home/x3/support/context.hpp>
  11. #include <boost/spirit/home/x3/support/unused.hpp>
  12. #include <boost/spirit/home/x3/core/skip_over.hpp>
  13. #include <boost/spirit/home/x3/core/parser.hpp>
  14. #include <boost/type_traits/remove_reference.hpp>
  15. #include <boost/utility/enable_if.hpp>
  16. namespace boost { namespace spirit { namespace x3
  17. {
  18. // same as lexeme[], but does not pre-skip
  19. template <typename Subject>
  20. struct no_skip_directive : unary_parser<Subject, no_skip_directive<Subject>>
  21. {
  22. typedef unary_parser<Subject, no_skip_directive<Subject> > base_type;
  23. static bool const is_pass_through_unary = true;
  24. static bool const handles_container = Subject::handles_container;
  25. no_skip_directive(Subject const& subject)
  26. : base_type(subject) {}
  27. template <typename Iterator, typename Context
  28. , typename RContext, typename Attribute>
  29. typename enable_if<has_skipper<Context>, bool>::type
  30. parse(Iterator& first, Iterator const& last
  31. , Context const& context, RContext& rcontext, Attribute& attr) const
  32. {
  33. auto const& skipper = x3::get<skipper_tag>(context);
  34. typedef unused_skipper<
  35. typename remove_reference<decltype(skipper)>::type>
  36. unused_skipper_type;
  37. unused_skipper_type unused_skipper(skipper);
  38. return this->subject.parse(
  39. first, last
  40. , make_context<skipper_tag>(unused_skipper, context)
  41. , rcontext
  42. , attr);
  43. }
  44. template <typename Iterator, typename Context
  45. , typename RContext, typename Attribute>
  46. typename disable_if<has_skipper<Context>, bool>::type
  47. parse(Iterator& first, Iterator const& last
  48. , Context const& context, RContext& rcontext, Attribute& attr) const
  49. {
  50. return this->subject.parse(
  51. first, last
  52. , context
  53. , rcontext
  54. , attr);
  55. }
  56. };
  57. struct no_skip_gen
  58. {
  59. template <typename Subject>
  60. no_skip_directive<typename extension::as_parser<Subject>::value_type>
  61. operator[](Subject const& subject) const
  62. {
  63. return { as_parser(subject) };
  64. }
  65. };
  66. auto const no_skip = no_skip_gen{};
  67. }}}
  68. #endif