not_predicate.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_OPERATOR_NOT_PREDICATE_HPP
  7. #define BOOST_SPIRIT_QI_OPERATOR_NOT_PREDICATE_HPP
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/qi/domain.hpp>
  12. #include <boost/spirit/home/qi/meta_compiler.hpp>
  13. #include <boost/spirit/home/qi/parser.hpp>
  14. #include <boost/spirit/home/qi/detail/attributes.hpp>
  15. #include <boost/spirit/home/support/has_semantic_action.hpp>
  16. #include <boost/spirit/home/support/handles_container.hpp>
  17. #include <boost/spirit/home/support/info.hpp>
  18. #include <boost/proto/operators.hpp>
  19. #include <boost/proto/tags.hpp>
  20. namespace boost { namespace spirit
  21. {
  22. ///////////////////////////////////////////////////////////////////////////
  23. // Enablers
  24. ///////////////////////////////////////////////////////////////////////////
  25. template <>
  26. struct use_operator<qi::domain, proto::tag::logical_not> // enables !p
  27. : mpl::true_ {};
  28. }}
  29. namespace boost { namespace spirit { namespace qi
  30. {
  31. template <typename Subject>
  32. struct not_predicate : unary_parser<not_predicate<Subject> >
  33. {
  34. typedef Subject subject_type;
  35. template <typename Context, typename Iterator>
  36. struct attribute
  37. {
  38. typedef unused_type type;
  39. };
  40. not_predicate(Subject const& subject_)
  41. : subject(subject_) {}
  42. template <typename Iterator, typename Context
  43. , typename Skipper, typename Attribute>
  44. bool parse(Iterator& first, Iterator const& last
  45. , Context& context, Skipper const& skipper
  46. , Attribute& /*attr*/) const
  47. {
  48. Iterator i = first;
  49. return !subject.parse(i, last, context, skipper, unused);
  50. }
  51. template <typename Context>
  52. info what(Context& context) const
  53. {
  54. return info("not-predicate", subject.what(context));
  55. }
  56. Subject subject;
  57. };
  58. ///////////////////////////////////////////////////////////////////////////
  59. // Parser generators: make_xxx function (objects)
  60. ///////////////////////////////////////////////////////////////////////////
  61. template <typename Elements, typename Modifiers>
  62. struct make_composite<proto::tag::logical_not, Elements, Modifiers>
  63. : make_unary_composite<Elements, not_predicate>
  64. {};
  65. }}}
  66. namespace boost { namespace spirit { namespace traits
  67. {
  68. ///////////////////////////////////////////////////////////////////////////
  69. template <typename Subject>
  70. struct has_semantic_action<qi::not_predicate<Subject> >
  71. : unary_has_semantic_action<Subject> {};
  72. ///////////////////////////////////////////////////////////////////////////
  73. template <typename Subject, typename Attribute, typename Context
  74. , typename Iterator>
  75. struct handles_container<qi::not_predicate<Subject>, Attribute
  76. , Context, Iterator>
  77. : unary_handles_container<Subject, Attribute, Context, Iterator> {};
  78. }}}
  79. #endif