not_predicate.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*=============================================================================
  2. Copyright (c) 2001-2014 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(BOOST_SPIRIT_X3_NOT_PREDICATE_MARCH_23_2007_0618PM)
  7. #define BOOST_SPIRIT_X3_NOT_PREDICATE_MARCH_23_2007_0618PM
  8. #include <boost/spirit/home/x3/core/parser.hpp>
  9. namespace boost { namespace spirit { namespace x3
  10. {
  11. template <typename Subject>
  12. struct not_predicate : unary_parser<Subject, not_predicate<Subject>>
  13. {
  14. typedef unary_parser<Subject, not_predicate<Subject>> base_type;
  15. typedef unused_type attribute_type;
  16. static bool const has_attribute = false;
  17. not_predicate(Subject const& subject)
  18. : base_type(subject) {}
  19. template <typename Iterator, typename Context
  20. , typename RContext, typename Attribute>
  21. bool parse(Iterator& first, Iterator const& last
  22. , Context const& context, RContext& rcontext, Attribute& /*attr*/) const
  23. {
  24. Iterator i = first;
  25. return !this->subject.parse(i, last, context, rcontext, unused);
  26. }
  27. };
  28. template <typename Subject>
  29. inline not_predicate<typename extension::as_parser<Subject>::value_type>
  30. operator!(Subject const& subject)
  31. {
  32. return { as_parser(subject) };
  33. }
  34. }}}
  35. #endif