sequence.hpp 3.7 KB

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