and_predicate.hpp 3.2 KB

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