and_predicate.hpp 3.2 KB

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