/src/contrib/boost/spirit/home/qi/operator/expect.hpp

http://pythonocc.googlecode.com/ · C++ Header · 92 lines · 66 code · 14 blank · 12 comment · 0 complexity · a56f49b466d9f270fe88ea88eb214b30 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2010 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_EXPECT_APRIL_29_2007_0445PM)
  7. #define SPIRIT_EXPECT_APRIL_29_2007_0445PM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/qi/operator/sequence_base.hpp>
  12. #include <boost/spirit/home/qi/detail/expect_function.hpp>
  13. #include <boost/spirit/home/qi/meta_compiler.hpp>
  14. #include <boost/spirit/home/support/info.hpp>
  15. #include <stdexcept>
  16. namespace boost { namespace spirit
  17. {
  18. ///////////////////////////////////////////////////////////////////////////
  19. // Enablers
  20. ///////////////////////////////////////////////////////////////////////////
  21. template <>
  22. struct use_operator<qi::domain, proto::tag::greater> // enables >
  23. : mpl::true_ {};
  24. template <>
  25. struct flatten_tree<qi::domain, proto::tag::greater> // flattens >
  26. : mpl::true_ {};
  27. }}
  28. namespace boost { namespace spirit { namespace qi
  29. {
  30. template <typename Iterator>
  31. struct expectation_failure : std::runtime_error
  32. {
  33. expectation_failure(Iterator first, Iterator last, info const& what)
  34. : std::runtime_error("boost::spirit::qi::expectation_failure")
  35. , first(first), last(last), what_(what)
  36. {}
  37. ~expectation_failure() throw() {}
  38. Iterator first;
  39. Iterator last;
  40. info what_;
  41. };
  42. template <typename Elements>
  43. struct expect : sequence_base<expect<Elements>, Elements>
  44. {
  45. friend struct sequence_base<expect<Elements>, Elements>;
  46. expect(Elements const& elements)
  47. : sequence_base<expect<Elements>, Elements>(elements) {}
  48. private:
  49. template <typename Iterator, typename Context, typename Skipper>
  50. static detail::expect_function<
  51. Iterator, Context, Skipper
  52. , expectation_failure<Iterator> >
  53. fail_function(
  54. Iterator& first, Iterator const& last
  55. , Context& context, Skipper const& skipper)
  56. {
  57. return detail::expect_function<
  58. Iterator, Context, Skipper, expectation_failure<Iterator> >
  59. (first, last, context, skipper);
  60. }
  61. std::string id() const { return "expect"; }
  62. };
  63. ///////////////////////////////////////////////////////////////////////////
  64. // Parser generators: make_xxx function (objects)
  65. ///////////////////////////////////////////////////////////////////////////
  66. template <typename Elements, typename Modifiers>
  67. struct make_composite<proto::tag::greater, Elements, Modifiers>
  68. : make_nary_composite<Elements, expect>
  69. {};
  70. }}}
  71. namespace boost { namespace spirit { namespace traits
  72. {
  73. template <typename Elements>
  74. struct has_semantic_action<qi::expect<Elements> >
  75. : nary_has_semantic_action<Elements> {};
  76. }}}
  77. #endif