expect.hpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #ifndef BOOST_SPIRIT_QI_OPERATOR_EXPECT_HPP
  8. #define BOOST_SPIRIT_QI_OPERATOR_EXPECT_HPP
  9. #if defined(_MSC_VER)
  10. #pragma once
  11. #endif
  12. #include <boost/spirit/home/qi/operator/sequence_base.hpp>
  13. #include <boost/spirit/home/qi/detail/expect_function.hpp>
  14. #include <boost/spirit/home/qi/detail/expectation_failure.hpp>
  15. #include <boost/spirit/home/qi/meta_compiler.hpp>
  16. #include <boost/spirit/home/support/has_semantic_action.hpp>
  17. #include <boost/spirit/home/support/handles_container.hpp>
  18. #include <boost/spirit/home/support/info.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::greater> // enables >
  28. : mpl::true_ {};
  29. template <>
  30. struct flatten_tree<qi::domain, proto::tag::greater> // flattens >
  31. : mpl::true_ {};
  32. }}
  33. namespace boost { namespace spirit { namespace qi
  34. {
  35. template <typename Elements>
  36. struct expect_operator : sequence_base<expect_operator<Elements>, Elements>
  37. {
  38. friend struct sequence_base<expect_operator<Elements>, Elements>;
  39. expect_operator(Elements const& elements)
  40. : sequence_base<expect_operator<Elements>, Elements>(elements) {}
  41. private:
  42. template <typename Iterator, typename Context, typename Skipper>
  43. static detail::expect_function<
  44. Iterator, Context, Skipper
  45. , expectation_failure<Iterator> >
  46. fail_function(
  47. Iterator& first, Iterator const& last
  48. , Context& context, Skipper const& skipper)
  49. {
  50. return detail::expect_function<
  51. Iterator, Context, Skipper, expectation_failure<Iterator> >
  52. (first, last, context, skipper);
  53. }
  54. std::string id() const { return "expect_operator"; }
  55. };
  56. ///////////////////////////////////////////////////////////////////////////
  57. // Parser generators: make_xxx function (objects)
  58. ///////////////////////////////////////////////////////////////////////////
  59. template <typename Elements, typename Modifiers>
  60. struct make_composite<proto::tag::greater, Elements, Modifiers>
  61. : make_nary_composite<Elements, expect_operator>
  62. {};
  63. }}}
  64. namespace boost { namespace spirit { namespace traits
  65. {
  66. ///////////////////////////////////////////////////////////////////////////
  67. template <typename Elements>
  68. struct has_semantic_action<qi::expect_operator<Elements> >
  69. : nary_has_semantic_action<Elements> {};
  70. ///////////////////////////////////////////////////////////////////////////
  71. template <typename Elements, typename Attribute, typename Context
  72. , typename Iterator>
  73. struct handles_container<qi::expect_operator<Elements>, Attribute, Context
  74. , Iterator>
  75. : mpl::true_ {};
  76. }}}
  77. #endif