no_skip.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  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(SPIRIT_NO_SKIP_JAN_16_2010_0802PM)
  8. #define SPIRIT_NO_SKIP_JAN_16_2010_0802PM
  9. #if defined(_MSC_VER)
  10. #pragma once
  11. #endif
  12. #include <boost/spirit/home/qi/meta_compiler.hpp>
  13. #include <boost/spirit/home/qi/skip_over.hpp>
  14. #include <boost/spirit/home/qi/parser.hpp>
  15. #include <boost/spirit/home/qi/detail/unused_skipper.hpp>
  16. #include <boost/spirit/home/support/unused.hpp>
  17. #include <boost/spirit/home/support/common_terminals.hpp>
  18. #include <boost/spirit/home/support/attributes.hpp>
  19. #include <boost/spirit/home/support/info.hpp>
  20. #include <boost/spirit/home/support/has_semantic_action.hpp>
  21. #include <boost/spirit/home/support/handles_container.hpp>
  22. #include <boost/utility/enable_if.hpp>
  23. namespace boost { namespace spirit
  24. {
  25. ///////////////////////////////////////////////////////////////////////////
  26. // Enablers
  27. ///////////////////////////////////////////////////////////////////////////
  28. template <>
  29. struct use_directive<qi::domain, tag::no_skip> // enables no_skip
  30. : mpl::true_ {};
  31. }}
  32. namespace boost { namespace spirit { namespace qi
  33. {
  34. #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
  35. using spirit::no_skip;
  36. #endif
  37. using spirit::no_skip_type;
  38. // same as lexeme[], but does not pre-skip
  39. template <typename Subject>
  40. struct no_skip_directive : unary_parser<no_skip_directive<Subject> >
  41. {
  42. typedef Subject subject_type;
  43. no_skip_directive(Subject const& subject_)
  44. : subject(subject_) {}
  45. template <typename Context, typename Iterator>
  46. struct attribute
  47. {
  48. typedef typename
  49. traits::attribute_of<subject_type, Context, Iterator>::type
  50. type;
  51. };
  52. template <typename Iterator, typename Context
  53. , typename Skipper, typename Attribute>
  54. typename disable_if<detail::is_unused_skipper<Skipper>, bool>::type
  55. parse(Iterator& first, Iterator const& last
  56. , Context& context, Skipper const& skipper
  57. , Attribute& attr_) const
  58. {
  59. return subject.parse(first, last, context
  60. , detail::unused_skipper<Skipper>(skipper), attr_);
  61. }
  62. template <typename Iterator, typename Context
  63. , typename Skipper, typename Attribute>
  64. typename enable_if<detail::is_unused_skipper<Skipper>, bool>::type
  65. parse(Iterator& first, Iterator const& last
  66. , Context& context, Skipper const& skipper
  67. , Attribute& attr_) const
  68. {
  69. return subject.parse(first, last, context
  70. , skipper, attr_);
  71. }
  72. template <typename Context>
  73. info what(Context& context) const
  74. {
  75. return info("no_skip", subject.what(context));
  76. }
  77. Subject subject;
  78. };
  79. ///////////////////////////////////////////////////////////////////////////
  80. // Parser generators: make_xxx function (objects)
  81. ///////////////////////////////////////////////////////////////////////////
  82. template <typename Subject, typename Modifiers>
  83. struct make_directive<tag::no_skip, Subject, Modifiers>
  84. {
  85. typedef no_skip_directive<Subject> result_type;
  86. result_type operator()(unused_type, Subject const& subject, unused_type) const
  87. {
  88. return result_type(subject);
  89. }
  90. };
  91. }}}
  92. namespace boost { namespace spirit { namespace traits
  93. {
  94. ///////////////////////////////////////////////////////////////////////////
  95. template <typename Subject>
  96. struct has_semantic_action<qi::no_skip_directive<Subject> >
  97. : unary_has_semantic_action<Subject> {};
  98. ///////////////////////////////////////////////////////////////////////////
  99. template <typename Subject, typename Attribute, typename Context
  100. , typename Iterator>
  101. struct handles_container<qi::no_skip_directive<Subject>, Attribute
  102. , Context, Iterator>
  103. : unary_handles_container<Subject, Attribute, Context, Iterator> {};
  104. }}}
  105. #endif