expect.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #if !defined(SPIRIT_EXPECT_APRIL_29_2007_0445PM)
  8. #define SPIRIT_EXPECT_APRIL_29_2007_0445PM
  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/meta_compiler.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. #include <stdexcept>
  19. namespace boost { namespace spirit
  20. {
  21. ///////////////////////////////////////////////////////////////////////////
  22. // Enablers
  23. ///////////////////////////////////////////////////////////////////////////
  24. template <>
  25. struct use_operator<qi::domain, proto::tag::greater> // enables >
  26. : mpl::true_ {};
  27. template <>
  28. struct flatten_tree<qi::domain, proto::tag::greater> // flattens >
  29. : mpl::true_ {};
  30. }}
  31. namespace boost { namespace spirit { namespace qi
  32. {
  33. template <typename Iterator>
  34. struct expectation_failure : std::runtime_error
  35. {
  36. expectation_failure(Iterator first_, Iterator last_, info const& what)
  37. : std::runtime_error("boost::spirit::qi::expectation_failure")
  38. , first(first_), last(last_), what_(what)
  39. {}
  40. ~expectation_failure() throw() {}
  41. Iterator first;
  42. Iterator last;
  43. info what_;
  44. };
  45. template <typename Elements>
  46. struct expect : sequence_base<expect<Elements>, Elements>
  47. {
  48. friend struct sequence_base<expect<Elements>, Elements>;
  49. expect(Elements const& elements)
  50. : sequence_base<expect<Elements>, Elements>(elements) {}
  51. private:
  52. template <typename Iterator, typename Context, typename Skipper>
  53. static detail::expect_function<
  54. Iterator, Context, Skipper
  55. , expectation_failure<Iterator> >
  56. fail_function(
  57. Iterator& first, Iterator const& last
  58. , Context& context, Skipper const& skipper)
  59. {
  60. return detail::expect_function<
  61. Iterator, Context, Skipper, expectation_failure<Iterator> >
  62. (first, last, context, skipper);
  63. }
  64. std::string id() const { return "expect"; }
  65. };
  66. ///////////////////////////////////////////////////////////////////////////
  67. // Parser generators: make_xxx function (objects)
  68. ///////////////////////////////////////////////////////////////////////////
  69. template <typename Elements, typename Modifiers>
  70. struct make_composite<proto::tag::greater, Elements, Modifiers>
  71. : make_nary_composite<Elements, expect>
  72. {};
  73. }}}
  74. namespace boost { namespace spirit { namespace traits
  75. {
  76. ///////////////////////////////////////////////////////////////////////////
  77. template <typename Elements>
  78. struct has_semantic_action<qi::expect<Elements> >
  79. : nary_has_semantic_action<Elements> {};
  80. ///////////////////////////////////////////////////////////////////////////
  81. template <typename Elements, typename Attribute, typename Context
  82. , typename Iterator>
  83. struct handles_container<qi::expect<Elements>, Attribute, Context
  84. , Iterator>
  85. : mpl::true_ {};
  86. }}}
  87. #endif