not_predicate.hpp 3.2 KB

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