sequence.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_SEQUENCE_APR_22_2006_0811AM)
  8. #define SPIRIT_SEQUENCE_APR_22_2006_0811AM
  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/fail_function.hpp>
  14. #include <boost/spirit/home/qi/meta_compiler.hpp>
  15. namespace boost { namespace spirit
  16. {
  17. ///////////////////////////////////////////////////////////////////////////
  18. // Enablers
  19. ///////////////////////////////////////////////////////////////////////////
  20. template <>
  21. struct use_operator<qi::domain, proto::tag::shift_right> // enables >>
  22. : mpl::true_ {};
  23. template <>
  24. struct flatten_tree<qi::domain, proto::tag::shift_right> // flattens >>
  25. : mpl::true_ {};
  26. }}
  27. namespace boost { namespace spirit { namespace qi
  28. {
  29. template <typename Elements>
  30. struct sequence : sequence_base<sequence<Elements>, Elements>
  31. {
  32. friend struct sequence_base<sequence<Elements>, Elements>;
  33. sequence(Elements const& elements)
  34. : sequence_base<sequence<Elements>, Elements>(elements) {}
  35. private:
  36. template <typename Iterator, typename Context, typename Skipper>
  37. static detail::fail_function<Iterator, Context, Skipper>
  38. fail_function(
  39. Iterator& first, Iterator const& last
  40. , Context& context, Skipper const& skipper)
  41. {
  42. return detail::fail_function<Iterator, Context, Skipper>
  43. (first, last, context, skipper);
  44. }
  45. std::string id() const { return "sequence"; }
  46. };
  47. ///////////////////////////////////////////////////////////////////////////
  48. // Parser generators: make_xxx function (objects)
  49. ///////////////////////////////////////////////////////////////////////////
  50. template <typename Elements, typename Modifiers>
  51. struct make_composite<proto::tag::shift_right, Elements, Modifiers>
  52. : make_nary_composite<Elements, sequence>
  53. {};
  54. // ///////////////////////////////////////////////////////////////////////////
  55. // // Define what attributes are compatible with a sequence
  56. // template <typename Attribute, typename Elements, typename Context, typename Iterator>
  57. // struct is_attribute_compatible<Attribute, sequence<Elements>, Context, Iterator>
  58. // : mpl::or_<
  59. // is_convertible<Attribute
  60. // , typename traits::attribute_of<sequence<Elements>, Context, Iterator>::type>
  61. // , traits::is_fusion_sequence_compatible<qi::domain, Attribute
  62. // , sequence<Elements>, Context, Iterator>
  63. // , traits::is_container_compatible<qi::domain, Attribute
  64. // , sequence<Elements>, Context, Iterator>
  65. // >
  66. // {};
  67. }}}
  68. namespace boost { namespace spirit { namespace traits
  69. {
  70. ///////////////////////////////////////////////////////////////////////////
  71. template <typename Elements>
  72. struct has_semantic_action<qi::sequence<Elements> >
  73. : nary_has_semantic_action<Elements> {};
  74. ///////////////////////////////////////////////////////////////////////////
  75. template <typename Elements, typename Attribute, typename Context
  76. , typename Iterator>
  77. struct handles_container<qi::sequence<Elements>, Attribute, Context
  78. , Iterator>
  79. : mpl::true_ {};
  80. }}}
  81. #endif