no_skip.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. namespace boost { namespace spirit
  23. {
  24. ///////////////////////////////////////////////////////////////////////////
  25. // Enablers
  26. ///////////////////////////////////////////////////////////////////////////
  27. template <>
  28. struct use_directive<qi::domain, tag::no_skip> // enables no_skip
  29. : mpl::true_ {};
  30. }}
  31. namespace boost { namespace spirit { namespace qi
  32. {
  33. #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
  34. using spirit::no_skip;
  35. #endif
  36. using spirit::no_skip_type;
  37. // same as lexeme[], but does not pre-skip
  38. template <typename Subject>
  39. struct no_skip_directive : unary_parser<no_skip_directive<Subject> >
  40. {
  41. typedef Subject subject_type;
  42. no_skip_directive(Subject const& subject_)
  43. : subject(subject_) {}
  44. template <typename Context, typename Iterator>
  45. struct attribute
  46. {
  47. typedef typename
  48. traits::attribute_of<subject_type, Context, Iterator>::type
  49. type;
  50. };
  51. template <typename Iterator, typename Context
  52. , typename Skipper, typename Attribute>
  53. bool parse(Iterator& first, Iterator const& last
  54. , Context& context, Skipper const& skipper
  55. , Attribute& attr_) const
  56. {
  57. return subject.parse(first, last, context
  58. , detail::unused_skipper<Skipper>(skipper), attr_);
  59. }
  60. template <typename Context>
  61. info what(Context& context) const
  62. {
  63. return info("no_skip", subject.what(context));
  64. }
  65. Subject subject;
  66. };
  67. ///////////////////////////////////////////////////////////////////////////
  68. // Parser generators: make_xxx function (objects)
  69. ///////////////////////////////////////////////////////////////////////////
  70. template <typename Subject, typename Modifiers>
  71. struct make_directive<tag::no_skip, Subject, Modifiers>
  72. {
  73. typedef no_skip_directive<Subject> result_type;
  74. result_type operator()(unused_type, Subject const& subject, unused_type) const
  75. {
  76. return result_type(subject);
  77. }
  78. };
  79. }}}
  80. namespace boost { namespace spirit { namespace traits
  81. {
  82. ///////////////////////////////////////////////////////////////////////////
  83. template <typename Subject>
  84. struct has_semantic_action<qi::no_skip_directive<Subject> >
  85. : unary_has_semantic_action<Subject> {};
  86. ///////////////////////////////////////////////////////////////////////////
  87. template <typename Subject, typename Attribute, typename Context
  88. , typename Iterator>
  89. struct handles_container<qi::no_skip_directive<Subject>, Attribute
  90. , Context, Iterator>
  91. : unary_handles_container<Subject, Attribute, Context, Iterator> {};
  92. }}}
  93. #endif