omit.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. =============================================================================*/
  6. #ifndef BOOST_SPIRIT_QI_DIRECTIVE_OMIT_HPP
  7. #define BOOST_SPIRIT_QI_DIRECTIVE_OMIT_HPP
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/qi/meta_compiler.hpp>
  12. #include <boost/spirit/home/qi/skip_over.hpp>
  13. #include <boost/spirit/home/qi/parser.hpp>
  14. #include <boost/spirit/home/support/unused.hpp>
  15. #include <boost/spirit/home/support/info.hpp>
  16. #include <boost/spirit/home/support/common_terminals.hpp>
  17. #include <boost/spirit/home/support/has_semantic_action.hpp>
  18. #include <boost/spirit/home/support/handles_container.hpp>
  19. namespace boost { namespace spirit
  20. {
  21. ///////////////////////////////////////////////////////////////////////////
  22. // Enablers
  23. ///////////////////////////////////////////////////////////////////////////
  24. template <>
  25. struct use_directive<qi::domain, tag::omit> // enables omit
  26. : mpl::true_ {};
  27. }}
  28. namespace boost { namespace spirit { namespace qi
  29. {
  30. #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
  31. using spirit::omit;
  32. #endif
  33. using spirit::omit_type;
  34. ///////////////////////////////////////////////////////////////////////////
  35. // omit_directive forces the attribute of subject parser
  36. // to be unused_type
  37. ///////////////////////////////////////////////////////////////////////////
  38. template <typename Subject>
  39. struct omit_directive : unary_parser<omit_directive<Subject> >
  40. {
  41. typedef Subject subject_type;
  42. omit_directive(Subject const& subject_)
  43. : subject(subject_) {}
  44. template <typename Context, typename Iterator>
  45. struct attribute
  46. {
  47. typedef unused_type type;
  48. };
  49. template <typename Iterator, typename Context
  50. , typename Skipper, typename Attribute>
  51. bool parse(Iterator& first, Iterator const& last
  52. , Context& context, Skipper const& skipper, Attribute& attr_) const
  53. {
  54. return subject.parse(first, last, context, skipper, attr_);
  55. }
  56. template <typename Context>
  57. info what(Context& context) const
  58. {
  59. return info("omit", subject.what(context));
  60. }
  61. Subject subject;
  62. };
  63. ///////////////////////////////////////////////////////////////////////////
  64. // Parser generators: make_xxx function (objects)
  65. ///////////////////////////////////////////////////////////////////////////
  66. template <typename Subject, typename Modifiers>
  67. struct make_directive<tag::omit, Subject, Modifiers>
  68. {
  69. typedef omit_directive<Subject> result_type;
  70. result_type operator()(unused_type, Subject const& subject, unused_type) const
  71. {
  72. return result_type(subject);
  73. }
  74. };
  75. }}}
  76. namespace boost { namespace spirit { namespace traits
  77. {
  78. ///////////////////////////////////////////////////////////////////////////
  79. template <typename Subject>
  80. struct has_semantic_action<qi::omit_directive<Subject> >
  81. : mpl::false_ {};
  82. ///////////////////////////////////////////////////////////////////////////
  83. template <typename Subject, typename Attribute, typename Context
  84. , typename Iterator>
  85. struct handles_container<qi::omit_directive<Subject>, Attribute
  86. , Context, Iterator>
  87. : unary_handles_container<Subject, Attribute, Context, Iterator> {};
  88. }}}
  89. #endif