omit.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #if !defined(SPIRIT_OMIT_MARCH_24_2007_0802AM)
  7. #define SPIRIT_OMIT_MARCH_24_2007_0802AM
  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. // silence MSVC warning C4512: assignment operator could not be generated
  63. BOOST_DELETED_FUNCTION(omit_directive& operator= (omit_directive const&))
  64. };
  65. ///////////////////////////////////////////////////////////////////////////
  66. // Parser generators: make_xxx function (objects)
  67. ///////////////////////////////////////////////////////////////////////////
  68. template <typename Subject, typename Modifiers>
  69. struct make_directive<tag::omit, Subject, Modifiers>
  70. {
  71. typedef omit_directive<Subject> result_type;
  72. result_type operator()(unused_type, Subject const& subject, unused_type) const
  73. {
  74. return result_type(subject);
  75. }
  76. };
  77. }}}
  78. namespace boost { namespace spirit { namespace traits
  79. {
  80. ///////////////////////////////////////////////////////////////////////////
  81. template <typename Subject>
  82. struct has_semantic_action<qi::omit_directive<Subject> >
  83. : mpl::false_ {};
  84. ///////////////////////////////////////////////////////////////////////////
  85. template <typename Subject, typename Attribute, typename Context
  86. , typename Iterator>
  87. struct handles_container<qi::omit_directive<Subject>, Attribute
  88. , Context, Iterator>
  89. : unary_handles_container<Subject, Attribute, Context, Iterator> {};
  90. }}}
  91. #endif